Elasticsearch入门 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

Index API


  Index API提供了几种创建Index方式。

  简单方式创建index

curl -XPUT ‘http://localhost:9200/twitter/'

  在创建索引的时候指定分片和副本数量参数,参数格式采用JSON格式。

curl -XPUT 'http://localhost:9200/twitter/' -d '{
  "settings":{
      "index":{
         "number_of_shards":3,
         "number_of_replicas":2
      }
  }
}’

  或者简化为

curl -XPUT 'http://localhost:9200/twitter' -d '{
  "settings":{
      "number_of_shards":3,
      "number_of_replicas":2
  }
}'

  另外的一种create index方式

curl -XPUT 'http://localhost:9200/twitter/tweet/1/_create' -d '{
  "user":"kimchy",
  "post_date":"2009-11-11T14:12:12",
  "message":"hello,world"
}'

  以上代码如果不指定id(即1),系统会自动生成id。

建立一个索引为twitter,类型为tweet,id为1的索引,其属性包括 _“user”:”kimchy”, “postdate”:”2009-11-11T14:12:12”, “message”:”hello,world”