2016-05-16 11 views
0

弾性検索でブール検索を使用しています。私のクエリは弾性検索のブール検索

curl -XGET 'localhost:9200/population/_search' -d '{ 
    "query":{ 
     "bool" : { 
      "must" : { 
       "term" : { "user" : "rahul" } 
      }, 
      "filter": { 
       "term" : { "message" : "dsi" } 
      }, 
      "must_not" : { 

        "country" : "pakistan" 

      }, 
      "should" : [ 
       { 
        "term" : { "country" : "india" } 
       }, 
       { 
        "term" : { "state" : "karnataka" } 
       } 
      ], 

      "minimum_should_match" : 1, 
      "boost" : 1.0 
     }} 

    }' 

です。ここで、ユーザーの国は私の弾性検索のフィールドです。 ですが、エラーが発生しています。

{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"population","line":13,"col":17}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"population","node":"bECY7K9ORPSuLrXpL1DpDw","reason":{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"population","line":13,"col":17}}]},"status":400} 

答えて

4

あなたbool/must_not句が正しくありません、あなたはplzはtermクエリ

curl -XGET 'localhost:9200/population/_search' -d '{ 
    "query":{ 
     "bool" : { 
      "must" : { 
       "term" : { "user" : "rahul" } 
      }, 
      "filter": { 
       "term" : { "message" : "dsi" } 
      }, 
      "must_not" : { 
       "term": { "country" : "pakistan" }  <--- change this line 
      }, 
      "should" : [ 
       { 
        "term" : { "country" : "india" } 
       }, 
       { 
        "term" : { "state" : "karnataka" } 
       } 
      ], 

      "minimum_should_match" : 1, 
      "boost" : 1.0 
     }} 

    }' 
+0

を逃している、私は何をする必要があるかの変更を私に説明しています。 –

+0

変更する行は1つだけです。私の更新された答えを見てください。 「国」:「国」:「パキスタン」ではなく「国」:「パキスタン」「 – Val

+0

」replyxyの問題が解決されました –