0

私のインデックスマッピングを以下に示します。

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
    }                              
  }
 }
}'

エラスティックサーチで次のクエリのアクションを実行する必要があります

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
}

したがって、クエリが間違っている場合は、このクエリを修正するのを手伝ってください。前もって感謝します。

4

1 に答える 1

0

"match"はフィルターではなくクエリであるため、フィルターとして使用しようとしたため、エラーが発生しています。これはあなたが望むことをするはずです("residentialKind"分析されていないと仮定して):

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

"residentialKind"IS が標準アナライザーなどで分析されている場合、これは機能するはずです。

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"}} 
                            ]
                        }
                    }
                 ]
             }
          }
       }
   }
}

テストに使用したコードは次のとおりです。

http://sense.qbox.io/gist/bbed61ef297b058c92d9c7f1523479dfeb3c35b2

于 2015-03-05T17:35:51.253 に答える