0 _search查询数据时可以指定多个index和type

GET /index1,index2/type1,type2/_search

GET /_all/type1/_search  相当于查询全部index下的type1的document

GET /_all/type1/_search?from=0&size=5 from和size为分页参数

1 增加一条数据,手动指定document的ID

PUT /index1/type1/1
{
"content1":"abcnt地方士大夫",
"age":"abc你的"
}

2 增加一条数据,自动指定document的ID

POST /index1/type1
{
"content1":"abcnt地方士大夫",
"age":"abc你的"
}

3 获取一条数据的方式,并指定查询返回字段

GET /index1/type1/1?_source=age,content1

4 es更新数据时使用自定义版本号,只有版本号大于当前版本号才允许更新操作

PUT /index1/type1/1?version=5&version_type=external  (之前的_version属性必须小于5)
{
"description":"程序员一枚~~~"
}

5 partial update对document中的部分field进行更新

POST /index1/type1/1/_update?version=13 (必须version等于当前版本号时才可以修改数据,而且内容和原来相同则认为未更改版本号不变;该操作在更新期间不会被打断)
{
"doc":{
"description":"程序员一枚~~~7778899056"
}
}

6 通过GET /_mget 批量查找数据,需要提供index,type,id(可以通过url参数增加,根据搜索范围不同使用不同的查询参数)

GET /_mget
{
"docs":[
{
"_index":"index1",
"_type":"type1",
"_id":"1",

  "_version":16
},
{
"_index":"index1",
"_type":"type1",
"_id":"2"
}
]
}

GET /index1/_mget
{
"docs":[
{
"_type":"type1",
"_id":"1",
"_version":16
},
{
"_type":"type1",
"_id":"2"
}
]
}

GET /index1/type1/_mget
{
"ids":[1,2]
}

7 _search搜索默认查询前10条(timeout=1ms可以指定超时时间)

GET /index1/type1/_search?timeout=1ms

8 使用_search?q=xxx,为全字段查询,如果使用_search?q=field:xxx为按照具体字段进行查询;

PUT /index3/type3/1
{
  "date":"2019-01-02",
  "name":"the little",
  "content":"Half the ideas in his talk were plagiarized from an article I wrote last month."
}

PUT /index3/type3/2
{
  "date":"2019-01-01",
  "name":"a dog",
  "content":"is the girl, women's attention and love day. July 7th Qiqiao customs, originated in the Han "
}

PUT /index3/type3/3
{
  "date":"2019-07-01",
  "name":"very tag",
  "content":"Some of our comrades love to write long articles with no substance, very much like the foot bindings of a slattern, long as well as smelly"
}

//但是按照具体字段查询时如果字段类型为date或者long等时间和数值类型则使用exact value去匹配
GET /index3/type3/_search?q=date:2019-01 //只能查询出1条数据,查询方式为exact value
GET /index3/type3/_search?q=2019-01 //则能查询出3条,因为会使用full text全字匹配,会将每一可能的部分都进行分词,只要包含则可以查询出来

 9 使用mapping指定索引字段的类型以及是否要进行分词,但是手动创建索引的mapping,只能给新字段指定,或者还没创建的索引指定,mapping不能修改

DELETE /index3

//创建索引并指定字段的属性
PUT /index3
{ 
  "mappings": {
    "type3": {
      "properties": {
        "date":{
          "type": "date"//日期类型的exact value匹配粗略除外,es会按照搜索的部分日期匹配出一个返回.如:GET /index3/type3/_search?q=date:2019 
        },
        "name":{
          "type": "keyword"
        },
        "no":{
           "type": "long"
        },
        "content":{
           "analyzer": "standard",
           "type": "string"
        }
      }
    }
  }
}

//添加数据
PUT /index3/type3/1
{
  "date":"2019-01-02",
  "name":"the little",
  "content":"Half the ideas in his talk were plagiarized from an article I wrote last month.",
  "no":"123"
}

PUT /index3/type3/2
{
  "date":"2019-01-01",
  "name":"a dog",
  "content":"is the girl, women's attention and love day. July 7th Qiqiao customs, originated in the Han ",
  "no":"6867858"
}

PUT /index3/type3/3
{
  "date":"2019-07-01",
  "name":"very tag",
  "content":"Some of our comrades love to write long articles with no substance, very much like the foot bindings of a slattern, long as well as smelly",
  "no":"123"
}

GET /index3/type3/_search?q=name:very tag  使用字段名称只能exact value策略匹配可以查询的到,因为type指定为keyword
View Code

相关文章:

  • 2021-06-19
  • 2021-08-09
  • 2021-12-04
  • 2021-11-15
  • 2021-07-17
  • 2021-09-24
  • 2021-09-25
  • 2022-01-16
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2021-05-19
  • 2021-12-12
  • 2021-11-20
  • 2021-09-30
  • 2021-08-17
相关资源
相似解决方案