elasticsearch,exact-match,nested-query,sql-match-all,Mysql,elasticsearch,Exact Match,Nested Query,Sql Match All" /> elasticsearch,exact-match,nested-query,sql-match-all,Mysql,elasticsearch,Exact Match,Nested Query,Sql Match All" />

Mysql 如何使用嵌套布尔过滤器在elasticsearch中查找同一字段上的精确匹配值?

Mysql 如何使用嵌套布尔过滤器在elasticsearch中查找同一字段上的精确匹配值?,mysql,elasticsearch,exact-match,nested-query,sql-match-all,Mysql,elasticsearch,Exact Match,Nested Query,Sql Match All,我的索引映射如下所示: curl -X PUT localhost:9200/testing/listings/_mapping -d '{ "listings" : { "properties" : { "address" : { "properties": { "location": { "type" : "string", "index" : "not_analyzed"

我的索引映射如下所示:

curl -X PUT localhost:9200/testing/listings/_mapping -d '{
 "listings" : {
  "properties" : {
    "address" : {
       "properties": {
          "location": { "type" : "string",
                        "index" : "not_analyzed"
           }
        }
    },
    "suggest" : { 
         "type" : "completion", 
         "index_analyzer" : "simple",
         "search_analyzer" : "simple",
         "payloads" : true
    }                              
  }
 }
}'
我需要在elasticsearch中执行以下查询操作

SELECT * FROM LISTINGS WHERE (published = true AND inActive = false) AND (residentialKind = "Villa" OR residentialKind = "Apartment");
为了执行上述查询操作,我在elasticsearch中使用了下面的嵌套bool查询

{"query":{
  "filtered": {
    "filter": {
        "bool":{
            "must":[
               {"match":{"published":true}},
               {"match":{"inActive":false}},
               {"bool":
                    {"should": [
                            {"term":{"residentialKind":"Villa"}},
                            {"term":{"residentialKind":"Apartment"}} 
                        ]
                    }
                }
             ]
         }
      }
   }
 }
}
它给出了如下错误

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[B5SbtdlkQTGL0WU-dvg2yg][propgod][0]: SearchParseException[[propgod][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\n\t\"filtered\": {\n    \t\"filter\": {\n     \t\t\"bool\":{\n      \t\t\t\"must\":[\n                   {\"match\":{\"published\":true}},\n                   {\"match\":{\"inActive\":false}},\n                   {\"bool\":\n                   \t\t{\"should\": [\n                        \t\t{\"term\":{\"residentialKind\":\"Villa\"}},\n                                {\"term\":{\"residentialKind\":\"Apartment\"}} \n                        \t]\n                       }\n                   }\n     \t\t\t]\n   \t\t\t}\n    \t}\n    }\n }\n}]]]; nested: QueryParsingException[[propgod] No filter registered for [match]]; }{[B5SbtdlkQTGL0WU-dvg2yg][propgod][1]: SearchParseException[[propgod][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\n\t\"filtered\": {\n    \t\"filter\": {\n     \t\t\"bool\":{\n      \t\t\t\"must\":[\n                   {\"match\":{\"published\":true}},\n                   {\"match\":{\"inActive\":false}},\n                   {\"bool\":\n                   \t\t{\"should\": [\n                        \t\t{\"term\":{\"residentialKind\":\"Villa\"}},\n                                {\"term\":{\"residentialKind\":\"Apartment\"}} \n                        \t]\n                       }\n                   }\n     \t\t\t]\n   \t\t\t}\n    \t}\n    }\n }\n}]]]; nested: QueryParsingException[[propgod] No filter registered for [match]]; }{[B5SbtdlkQTGL0WU-dvg2yg][propgod][2]: SearchParseException[[propgod][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\n\t\"filtered\": {\n    \t\"filter\": {\n     \t\t\"bool\":{\n      \t\t\t\"must\":[\n                   {\"match\":{\"published\":true}},\n                   {\"match\":{\"inActive\":false}},\n                   {\"bool\":\n                   \t\t{\"should\": [\n                        \t\t{\"term\":{\"residentialKind\":\"Villa\"}},\n                                {\"term\":{\"residentialKind\":\"Apartment\"}} \n                        \t]\n                       }\n                   }\n     \t\t\t]\n   \t\t\t}\n    \t}\n    }\n }\n}]]]; nested: QueryParsingException[[propgod] No filter registered for [match]]; }{[B5SbtdlkQTGL0WU-dvg2yg][propgod][3]: SearchParseException[[propgod][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\n\t\"filtered\": {\n    \t\"filter\": {\n     \t\t\"bool\":{\n      \t\t\t\"must\":[\n                   {\"match\":{\"published\":true}},\n                   {\"match\":{\"inActive\":false}},\n                   {\"bool\":\n                   \t\t{\"should\": [\n                        \t\t{\"term\":{\"residentialKind\":\"Villa\"}},\n                                {\"term\":{\"residentialKind\":\"Apartment\"}} \n                        \t]\n                       }\n                   }\n     \t\t\t]\n   \t\t\t}\n    \t}\n    }\n }\n}]]]; nested: QueryParsingException[[propgod] No filter registered for [match]]; }{[B5SbtdlkQTGL0WU-dvg2yg][propgod][4]: SearchParseException[[propgod][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\n\t\"filtered\": {\n    \t\"filter\": {\n     \t\t\"bool\":{\n      \t\t\t\"must\":[\n                   {\"match\":{\"published\":true}},\n                   {\"match\":{\"inActive\":false}},\n                   {\"bool\":\n                   \t\t{\"should\": [\n                        \t\t{\"term\":{\"residentialKind\":\"Villa\"}},\n                                {\"term\":{\"residentialKind\":\"Apartment\"}} \n                        \t]\n                       }\n                   }\n     \t\t\t]\n   \t\t\t}\n    \t}\n    }\n }\n}]]]; nested: QueryParsingException[[propgod] No filter registered for [match]]; }]",
"status": 400
}
因此,如果我的查询出错,请帮助我修复此查询。提前感谢。

是一个查询,而不是一个筛选器,因此您会收到一个错误,因为您试图将其用作筛选器。这应该满足您的要求(假设未分析
“residentialKind”
):

如果使用标准分析仪之类的工具分析“residentialKind”,则该功能应能正常工作:

POST /test_index/_search
{
    "query": {
        "bool":{
            "must":[
               {"match":{"published":true}},
               {"match":{"inActive":false}},
               {"bool":
                    {"should": [
                            {"match":{"residentialKind":"Villa"}},
                            {"match":{"residentialKind":"Apartment"}} 
                        ]
                    }
                }
             ]
         }
    }
}
甚至

POST /test_index/_search
{
    "query":{
      "filtered": {
        "filter": {
            "bool":{
                "must":[
                   {"term":{"published":true}},
                   {"term":{"inActive":false}},
                   {"bool":
                        {"should": [
                                {"term":{"residentialKind":"villa"}},
                                {"term":{"residentialKind":"apartment"}} 
                            ]
                        }
                    }
                 ]
             }
          }
       }
   }
}
以下是我用于测试的代码:

如果“residentialKind”字段包含“residentialKind”:“Row House”或“residentialKind”:“Individual House”这样的值,那么我应该分析该字段吗?如果是,那么映射或查询需要做哪些更改?斯隆,请帮帮我
POST /test_index/_search
{
    "query":{
      "filtered": {
        "filter": {
            "bool":{
                "must":[
                   {"term":{"published":true}},
                   {"term":{"inActive":false}},
                   {"bool":
                        {"should": [
                                {"term":{"residentialKind":"villa"}},
                                {"term":{"residentialKind":"apartment"}} 
                            ]
                        }
                    }
                 ]
             }
          }
       }
   }
}