2017-03-07 201 views
0

這裏是一個文檔的結構,由彈性搜索API爲退貨:彈性搜索嵌套過濾

{ "process_name":"process01", "beat": { "hostname":"12345","name":"blablabla" }, }

過濾通過PROCESS_NAME很容易,但如何將host_name過濾,這是內部嵌套擊敗?

  • 失敗嘗試1

{ "size":10000, "query" : { "bool" : { "should": [ { "match" : { "process_name" : "process01" } }, { "match" : { "process_name" : "process02" } } ], "must": [ { "match" : { beat: { "hostname":"12345" } } } ] } } }

錯誤消息1:

(失敗的反序列化對象類型=類com.logshero.api.SearchApiRequest):

  • 失敗嘗試2

{ "size":10000, "query" : { "bool" : { "should": [ { "match" : { "process_name" : "process01" } }, { "match" : { "process_name" : "process02" } } ], "must": [ { "match" : { "hostname":"12345" } } ] } } }

錯誤消息2:

{ 「命中」:{ 「總」:0, 「MAX_SCORE」:空, 「命中」:[] }}

回答

1

您可以使用以下查詢。您還必須確保映射中的節拍定義爲嵌套類型。

{ 
    "size": 10000, 
    "query": { 
     "bool": { 
      "should": [{ 
       "match": { 
        "process_name": "process01" 
       } 
      }, { 
       "match": { 
        "process_name": "process02" 
       } 
      }], 
      "must": [{ 
       "match": { 
        "beat.hostname": "12345" 
       } 
      }] 
     } 
    } 
} 

感謝

+0

它的工作!非常感謝! –