2017-08-16 5 views
0

boolを使用してクエリを実行するときにpython-elasticsearchまたはcurlを使用して適切な結果を返そうとしています。Elasticsearch '複数の条件でクエリする'

私はこの文書が私の質問にあると知っています。私はそれを 'should'で見つけることができます。しかし、私は両方の基準を満たす必要がありますので、私は 'must'と同じクエリを実行しようとします。 「必須」を使用すると、問題の文書は返されません。万一付き

しなければならないと

$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query" : { 
     "constant_score" : { 
     "filter" : { 
      "bool" : { 
       "should" : [ 
       { "term" : {"project" : "AMQ"}}, 
       { "term" : {"test-type" : "functional"}}] 
      } 
     } 
     } 
    } 
} 
' 

"hits" : { 
    "total" : 3, 
    "max_score" : 1.0, 
    "hits" : [ 
     { 
     "_index" : "polarion", 
     "_type" : "subtype1", 
     "_id" : "AV3s-vbF8T4AI9Zj3GkM", 
     "_score" : 1.0, 
     "_source" : { 
      "project" : "AMQ", 
      "query" : "test-metrics", 
      "test-type" : "functional", 
      "2017-08-16" : 1916 
     } 
     }, 

$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query" : { 
     "constant_score" : { 
     "filter" : { 
      "bool" : { 
       "must" : [ 
       { "term" : {"project" : "AMQ"}}, 
       { "term" : {"test-type" : "functional"}}] 
      } 
     } 
     } 
    } 
} 
' 


{ "took" : 0, "timed_out" : false, "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 }, "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] } } 
+1

'project'フィールドが解析されている(つまり、' text'型であるためです)代わりに 'match'クエリを使用するか、' term'を使うことができますが、 'AMQ'の代わりに小文字で' amq'を検索してください – Val

+0

上記のValのコメントに追加するか、テキストタイプからキーワードにマッピングを変更することができますタイプを入力すると、その正確な値としての用語に一致します – Rahul

答えて

0

変更

{"term": {"project": "AMQ"}} 

{"term": {"project": "amq"}} 

または、一致する用語を 'AMQ'で置き換えることができます。

+0

これはこの特定の問題を解決しますが、[this](https://stackoverflow.com/questions/45077406/elasticsearch-multiple-exact-search-on-field-returns- no-results/45103907#45103907)が面白いかもしれません。 – Slomo

関連する問題