0
這是我的映射看起來像ElasticSearch has_child查詢不支持QUERY_STRING
{
"state":"open",
"settings":{
"index":{
"creation_date":"1453816191454",
"number_of_shards":"5",
"number_of_replicas":"1",
"version":{
"created":"1070199"
},
"uuid":"TfMJ4M0wQDedYSQuBz5BjQ"
}
},
"mappings":{
"Product":{
"properties":{
"index":"not_analyzed",
"store":true,
"type":"string"
},
"ProductName":{
"type":"nested",
"properties":{
"Name":{
"store":true,
"type":"string"
}
}
},
"ProductCode":{
"type":"string"
},
"Number":{
"index":"not_analyzed",
"store":true,
"type":"string"
},
"id":{
"index":"no",
"store":true,
"type":"integer"
},
"ShortDescription":{
"store":true,
"type":"string"
},
"Printer":{
"_routing":{
"required":true
},
"_parent":{
"type":"Product"
},
"properties":{
"properties":{
"RelativeUrl":{
"index":"no",
"store":true,
"type":"string"
}
}
},
"PrinterId":{
"index":"no",
"store":true,
"type":"integer"
},
"Name":{
"store":true,
"type":"string"
}
}
},
"aliases":[
]
}
}
我想查詢打印機的子對象,並取回產品。當我用下面的查詢語句查詢時,它適用於2230的情況,但是當我給hl-2230時,它不返回任何內容,因爲分析了名稱字段。在這種情況下,我需要query_string來獲得預期的結果。
{
"query": {
"has_child": {
"type": "Printer",
"query": {
"term": {
"Name": "2230"
}
}
}
}
}
當我嘗試查詢那樣我收到[has_child]查詢不支持[query_string]]。我嘗試匹配查詢,並得到相同的消息。 has_child只能使用術語查詢嗎?如果情況如此,我怎麼能達到預期的結果?
"query": {
"has_child": {
"type": "Printer",
"query_string": {
"default_field": "Name",
"query": "HL-2230"
}
}
哇,這很簡單。如果我可能會問你一個問題,那麼哪個查詢可能會返回「hl2230」的結果。如果名稱被索引爲「hl-2230」。它甚至有可能嗎? – batmaci
由於您的'hl-2230'被分析並具有'generic_analyzer'。它將被標記爲'hl'和'2230'。這意味着在'reverse index'中沒有保存爲'hl2230'的標記。因此,如果您查詢'hl2230',您無法獲得結果。但是你可以通過改變指數分析器來獲得結果,但這需要重新索引你的指數 – Richa
你能給我一些關於這方面的提示嗎?我也提出了一個單獨的問題。 http://stackoverflow.com/questions/35697941/which-analyzer-to-get-results-of-appended-words-when-data-has-space-or-dash-in-b – batmaci