创建索引操作语句:

put /ads_es_abc_index   //这里只填写索引名称即可
{
   "settings": {       //在setting中设置该索引的分片副本以及自动刷新时间等设置
       "number_of_shards": 3,
       "number_of_replicas": 2
   },
   "mappings": {    //mapping中就是当前索引的字段
       "properties": {
           "id": {
               "type": "long",
               "index": false // 是否被索引,如果为true就会被索引,会被查询到,为false则不会被查询到
           },
           "name": {
               "type": "keyword",
               "index": true
           },
           "address": {
               "type": "keyword", // 关键字;如果根据这个字段进行查询必须是全名称,负责搜索不到对应内容
               "index": true
           }
       }
   }
}

查询索引操作:

get /ads_es_index(索引名称)/_cat/indices?v

查询文档:

get /es_index(索引名称)/_search      //精确查询
{
	"query":{
		"bool":{
			"filter":{
				"term":{
				"field(需要查询的字段名)":"value(查询字段的值)"
				}
			}
		}
	}
}

get /es_index(索引名)/_doc/id(文档主键)



GET /user/_search     //范围查询
{
  "query":{
  "range":{
      "age":{
        "gte": 5,       //gte 是大于等于 gt是大于
        "lte": 18		//lte是小于等于 lt是小于
      }
    }
  }
}
 

新增文档操作:

put /es_index(索引名)/_doc/id
{
	"name":"张三",
	"age":"18",
	"length":"180"
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐