43.初识搜索引擎_常用的各种query搜索语法

1、match all 查询全部

 

GET /_search
{
    "query": {
        "match_all": {}
    }
}

2、match 指定条件查询

 

GET /_search
{
  "query": {
    "match": {
      "test_content": "automatic"
    }
  }
}

3、multi match 同一field多条件查询

query:要查询的内容
fields:要查询的field字段

 

GET /_search
{
  "query": {
    "multi_match": {
      "query": "client",
      "fields": ["test_field1","test_field2"]
    }
  }
}

4、range query 对比查询

查询年龄大于30的数据

 

GET /company/employee/_search
{
  "query": {
    "range": {
      "age": {
        "gte": 30
      }
    }
  }
}

5、term query 不会对查询条件进行分词

如果查询条件未分词,但是查询的数据field是分词的,会有可能查询不到结果

 

GET /test_index/test_type/_search 
{
  "query": {
    "term": {
      "test_field": "test client 2"
    }
  }
}

6、terms query 查询多个内容,并且不分词

 

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

7、exist query(2.x中的查询,现在已经不提供了)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章