2017-04-20 76 views
1

enter image description here我怎樣寫在彈性搜索查詢時,字段名稱是未知

我想用彈性搜索查詢誰擁有「dc883c6f24776ad6ce1f86c41b5cf87cfb784e85」的匹配值的文檔。

請查看圖像中附加的源文檔的結構。當字段名稱對我們來說是未知的時候,是否可以使用* [wild char]來查詢下面的內容。

"query" : { 
    "constant_score" : { 
     "filter" : { 
      "terms" : { 
       "commitId.persistence-statics-service.*":["dc883c6f24776ad6ce1f86c41b5cf87cfb784e85"] 
      } 
     } 
    } 
} 

回答

0

您可以使用query_stringmulti_match指定字段名部分的通配符。我認爲multi_match更簡單:

{ 
    "query": { 
    "constant_score": { 
     "filter": { 
     "multi_match": { 
      "query": "dc883c6f24776ad6ce1f86c41b5cf87cfb784e85", 
      "fields": [ 
      "commitId.persistence-statics-service.*" 
      ], 
      "analyzer": "keyword" 
     } 
     } 
    } 
    } 
} 
0

嘗試使用query_string。它在ES部分搜索功能非常強大,檢查我的回答link: -

{ 
    "query": { 
    "query_string": { 
     "fields" : ["commitId.persistence-statics-service.*"] , 
     "query": "*dc883c6f24776ad6ce1f86c41b5cf87cfb784e85*" 
    } 
    } 
} 

QUERY_STRING比multi_match更強大link2