1. 程式人生 > >50.常用的query查詢方式

50.常用的query查詢方式

log IT bsp query count pos tle add ron

主要知識點

  • match all
  • match
  • multi match
  • range query
  • term query
  • terms query
  • exist query

1match all

查詢所有

GET /_search

{

"query": {

"match_all": {}

}

}

示例:

GET /company/employee/_search

{

"query": {

"match_all": {}

}

}

2match

GET /_search

{

"query": { "match": { "title": "my elasticsearch article" }}

}

示例:

GET /company/employee/_search

{

"query": {

"match": {

"age": "27"

}

}

}

3multi match

GET /test_index/test_type/_search

{

"query": {

"multi_match": {

"query": "test",

"fields": ["test_field", "test_field1"]

}

}

}

示例:

GET /company/employee/_search

{

"query": {

"multi_match": {

"query": "china",

"fields": ["address.city","address.country","address.province"]

}

}

}

4range query

GET /company/employee/_search

{

"query": {

"range": {

"age": {

"gte": 30

}

}

}

}

示例:

GET /company/employee/_search

{

"query": {

"range": {

"age": {

"gte": 30

}

}

}

}

5term query

不分詞,必須精確匹配

GET /test_index/test_type/_search

{

"query": {

"term": {

"test_field": "test hello"

}

}

}

6terms query

不分詞,必須精確匹配

GET /_search

{

"query": { "terms": { "tag": [ "search", "full_text", "nosql" ] }}

}

7exist query

2.x中的查詢,現在已經不提供了)

50.常用的query查詢方式