1. 程式人生 > >ElasticSearch最佳入門實踐(四十九)各種query搜尋語法

ElasticSearch最佳入門實踐(四十九)各種query搜尋語法

1、match all

查詢所有

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

2、match

匹配某一個filed是否包含文字

GET /_search
{
    "query": { "match": { "title": "my elasticsearch article" }}
}

3、multi match

可以把搜尋到的文字放到多個field上去

GET /test_index/test_type/_search
{
  "query": {
    "multi_match": {
      "query": "test",
      "fields": ["test_field", "test_field1"]
    }
  }
}

4、range query

範圍查詢
年齡 >= 30的員工


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

5、term query

會把這個欄位當成 exact value 全匹配來查詢 不會進行分詞

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

6、terms query

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

7、exist query(2.x中的查詢,現在已經不提供了)

這個欄位不能為空

GET /test_index/test_type/_search 
{
  "query": {
    "exists": {
      "field": "title"
    }
  }
}