2017-06-05 102 views
0

我在Elasticsearch以下數據索引使用以下語法:查詢嵌套陣列中Elasticsearch

PUT /try1 
{ 
"mappings" : { 
    "product" : { 
    "properties" : { 
    "name": { "type" : "text" }, 
    "categories": { 
     "type": "nested", 
     "properties": { 
     "range":{"type":"text"} 
     } 
    } 
    } 
    } 
} 
} 

範圍類型具有單詞的數組:[「高」,「中」,「低」 ] 我需要訪問嵌套類別內的範圍元素。我試着用下面的語法:

GET /try1/product/_search 
{ 
    "query": { 
     "nested" : { 
      "path" : "categories", 
      "query" : { 
       "bool" : { 
        "must" : [ 
        { "match" : {"categories.range": "low"} } 
        ] 
       } 
      } 
     } 
    } 

} 

不過,我正在與消息的錯誤: 「理由」:「」,「無法創建查詢:...

可有人請提供解決這個

+0

你如何運行你的查詢?使用編程語言或...?您的查詢似乎是正確的。我建議你使用'chrome sense extension'運行查詢並提供完整的錯誤。 –

回答

0

@KGB可以嘗試讓你的查詢略有不同是這樣的:

{ 
    "query": { 
     "bool": { 
      "must": [ 
       { 
        "match": { 
         "categories.range": "low" 
        } 
       } 
      ] 
     } 
    } 
} 
0
{ 
    "query": { 
     "nested" : { 
      "path" : "categories", 
      "query" : { 
       "bool" : { 
        "must" : [ 
        { categories.range": "low"} 
        ] 
       } 
      } 
     } 
    } 
} 

這工作完美