美文网首页
es 创建动态索引(一)

es 创建动态索引(一)

作者: 良人与我 | 来源:发表于2019-05-30 20:39 被阅读0次

es 实体类

/**
 * @author river
 * @date 2019/2/27 14:47
 **/
@Data
@Document(indexName = "student-" + "#{ T(com.river.es.entity.Student).dateStr() }",

        type = "student",
        shards = 2,
        replicas = 1, refreshInterval = "-1")
public class Student {

    @Id
    private String id;

    private String name;

    private Integer age;

    private String desc;

    public static String dateStr()
    {
        return DateUtil.now().replace(" ","");
    }
}

索引的后缀是时间,精确到秒钟
测试方法,每隔一秒钟插入一条数据。

    @Test
    public void testsave() throws InterruptedException {
        for (int i = 0; i < 5 ; i++) {
            Thread.sleep(1000);
            Student student = new Student();
            student.setName("name:"+i);
            studentService.save(student);
        }
    }

通过kibana 去查询结果


GET /student*/_search?pretty
{
  "query": {
    "match_all": {}
  }
}

结果如下 发现的确创建了多个索引

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 27,
    "successful": 27,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 5,
    "max_score": 1,
    "hits": [
      {
        "_index": "student-2019-05-3020:09:38",
        "_type": "student",
        "_id": "nPalCGsBUgUE7dzSTPac",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:0",
          "age": null,
          "desc": null
        }
      },
      {
        "_index": "student-2019-05-3020:09:41",
        "_type": "student",
        "_id": "nvalCGsBUgUE7dzSVvYo",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:2",
          "age": null,
          "desc": null
        }
      },
      {
        "_index": "student-2019-05-3020:09:42",
        "_type": "student",
        "_id": "n_alCGsBUgUE7dzSW_YE",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:3",
          "age": null,
          "desc": null
        }
      },
      {
        "_index": "student-2019-05-3020:09:43",
        "_type": "student",
        "_id": "oPalCGsBUgUE7dzSX_bT",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:4",
          "age": null,
          "desc": null
        }
      },
      {
        "_index": "student-2019-05-3020:09:40",
        "_type": "student",
        "_id": "nfalCGsBUgUE7dzSUfZj",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:1",
          "age": null,
          "desc": null
        }
      }
    ]
  }
}

参考地址
https://www.jianshu.com/p/0b603db1278f
https://www.dingdangss.com/2017/04/05/%E5%88%A9%E7%94%A8springAOP-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3-SpEL%E5%AE%9E%E7%8E%B0%E6%93%8D%E4%BD%9C%E6%97%A5%E5%BF%97%E8%AE%B0%E5%BD%95/

相关文章

  • es 创建动态索引(一)

    es 实体类 索引的后缀是时间,精确到秒钟测试方法,每隔一秒钟插入一条数据。 通过kibana 去查询结果 结果如...

  • es 创建动态索引(二)

    上一篇文章es 创建动态索引(一) ,通过el表达式 修改 @Document 里 indexName 值,实现...

  • ES 相关语句

    ES: 查看索引 添加 创建索引 创建类型 查询

  • Elasticsearch 7 : 自定义 mapping 和

    ES 7 中在创建索引时指定 Mapping ES 7 中先建索引,再自定义 mapping ES 7 建索引时指...

  • ElasticSearch的Java操作

    java 连接ES 创建client链接 创建索引 检查索引是否存在,删除索引 检查索引存在 删除索引 Java操...

  • elasticsearch 的 python API

    导入 es 创建索引 其中的 acknowledged 字段表示创建操作执行成功 重复创建索引,会引发 400 错...

  • ElasticSearch的基本操作

    操作ES的RESTful语法 索引的操作 1、创建一个索引 2、查看一个索引 3、删除一个索引 3.4 ES中Fi...

  • 三、Es文档

    Es索引 1、创建单一文档 2、批量创建文档

  • python对es基础的增删改查

    安装API python对索引进行操作 建立es连接 创建索引 删除索引 判断索引存在 对索引加入mapping ...

  • ES的基础使用

    索引模板 如果更改了模板不能对已存在索引生效 创建索引 下面创建一个名字为 laravel_es 的模板,mapp...

网友评论

      本文标题:es 创建动态索引(一)

      本文链接:https://www.haomeiwen.com/subject/hirbtctx.html