我是Elasticsearch的新手,我需要在我的match_phrase查询中使用模糊性,但是还没有找到合适的帮助文档。由于我的映射也是嵌套的,因此获取正确的查询几乎没有什么麻烦。
映射
{
"mappings":{
"type":{
"properties":{
"Id":{
"type":"integer"
},
"custom":{
"type":"nested",
"properties":{
"text":{
"type":"text"
},
"start_time":{
"type":"text"
},
"end_time":{
"type":"text"
}
}
}
}
}
}
}
POST http://localhost:9200/transcripts/type/_search
{
"query":{
"nested":{
"path":"custom",
"query":{
"match_phrase":{
"custom.text":"search something here",
"fuzziness":"2"
}
},
"inner_hits":{
"highlight":{
"fields":{
"custom.start_time":{}
}
}
}
}
}
}
输出
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[match_phrase] query doesn't support multiple fields, found [custom.text] and [fuzziness]",
"line": 8,
"col": 26
}
],
"type": "parsing_exception",
"reason": "[match_phrase] query doesn't support multiple fields, found [custom.text] and [fuzziness]",
"line": 8,
"col": 26
},
"status": 400
}
答案 0 :(得分:0)
这意味着您的查询格式不正确。 查阅有关匹配查询的以下文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
您的嵌套查询似乎应如下所示:
{
"query": {
"match" : {
"custom.text" : {
"query" : "search something here",
"fuzziness": "2"
}
}
}
}
因此,您的查询应为:
{
"query":{
"nested":{
"path":"custom",
"query":{
"match":{
"custom.text": {
"query" : search something here",
"fuzziness":"2"
}
}
},
"inner_hits":{
"highlight":{
"fields":{
"custom.start_time":{}
}
}
}
}
}
}