【问题标题】:Nested Elasticsearch match_phrase with fuzzy quotient fails具有模糊商的嵌套 Elasticsearch match_phrase 失败
【发布时间】:2019-04-02 06:24:42
【问题描述】:

我对 elasticsearch 相当陌生,我需要在 match_phrase 查询中使用模糊性,但没有找到合适的帮助文档。由于我的映射也是嵌套的,因此我可以轻松获得正确的查询。

映射

{
    "mappings":{
        "type":{
            "properties":{
                "Id":{
                    "type":"integer"
                },
                "custom":{
                    "type":"nested",
                    "properties":{
                        "text":{
                            "type":"text"
                        },
                        "start_time":{
                            "type":"text"
                        },
                        "end_time":{
                            "type":"text"
                        }

                    }
                }
            }
        }
    }
}

发布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
}

【问题讨论】:

  • 检查我的答案!希望有帮助!

标签: elasticsearch postman


【解决方案1】:

这意味着您的查询格式错误。 查看有关匹配查询的文档: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":{}
                }
            }
         }
      }
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-24
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    相关资源
    最近更新 更多