2015-05-11 141 views
0

在此示例中,我已將完整查詢示例放置到已阻止的非工作部分。嵌套過濾器中的query_string過濾器會引發錯誤

基本上我們有一個文件,在datailItems下有一個嵌套的文檔類型,並試圖對該嵌套文檔中的字段執行query_string過濾器失敗。我採取相同的部分,並運行它對一個非嵌套的領域,它的工作原理。所以顯然我做錯了什麼。

我收到的錯誤是nested: QueryParsingException[[******] [_na] filter malformed, must start with start_object]

那麼,什麼是做到這一點的正確方法?

一些注意事項。 「和」被用於包含布爾,範圍等的進一步的過濾器要求......我已經刪除了這個例子的附加要求。

{ 
    "size" : 1, 
    "query" : { 
     "filtered" : { 
      "filter" : { 
       "and" : [{ 
         "nested" : { 
          "path" : "detailItems", 
          "filter" : { 
           "and" : [{ 
             "query" : { 
              "query_string" : { 
               "detailItems.name" : { 
                "query" : "mastersettings", 
                "minimum_should_match" : 1 
               } 
              } 
             } 
            } 
           ] 
          } 
         } 
        } 
       ] 
      } 
     } 
    } 
} 
+0

只有走'query_string'部分,包括現場' detailItems.name'並在該大型查詢之外進行測試。事情是這樣的'{ 「查詢」:{ 「嵌套」:{ 「路徑」: 「detailItems」, 「查詢」:{ 「QUERY_STRING」:{ 「田」: 「detailItems.name」 ], 「查詢」: 「mastersettings」, 「minimum_should_match」:1 } } } } }' –

+0

好了,它看起來像我必須把它完全是出於一種嵌套過濾器的工作 '{ 「size」:1, 「query」:{ 「過濾」:{ 「過濾器」:{ 「查詢」:{ 「QUERY_STRING」:{ 「detailItems.name」:{ 「查詢」: 「mastersettings」, 「minimum_should_match」:1 } } } } } } }' – danatcofo

回答

0

在OP的query_string沒有語法正確,下面是查詢字符串可以重寫如何一個例子:

"size" : 1, 
    "query" : { 
     "filtered" : { 
      "filter" : { 
       "and" : [{ 
         "nested" : { 
          "path" : "detailItems", 
          "filter" : { 
           "and" : [{ 
             "query" : { 
              "query_string" : { 
               "fields": [ 
                "detailItems.name" 
               ], 
               "query" : "mastersettings", 
               "minimum_should_match" : 1 

              } 
             } 
            } 
           ] 
          } 
         } 
        } 
       ] 
      } 
     } 
    } 
+0

Yah我得到了這個來運行自己,但我實際上無法得到它返回結果。爲什麼我原來的工作不在嵌套上下文中而不在裏面? – danatcofo

+0

儘管這並沒有解決我的目標,但它是解決問題的方法。謝謝@凱蒂 – danatcofo