2016-12-05 9 views
3

私は、Python API経由でESサーバーを照会するときに、複数のフィールドを照合しようとしています。しかし、Python内の構文を理解することはできません:弾性検索 - Pythonクライアント - 複数のフィールドのマッチング方法?

私は試しました。

res = es.search(index="pyats", doc_type="router_show", body={"query": {"match": {"name": "mark"} AND {"age": "21"}}}, size=1000) 

res = es.search(index="pyats", doc_type="router_show", body={"query": {"match_all": {"name": "mark"} AND {"age": "21"}}}, size=1000) 

res = es.search(index="pyats", doc_type="router_show", body={"query": {"match": {"name": "mark"}}, {"match": {"age": "21"}}}, size=1000) 

任意のアドバイスを大幅に理解されるであろう。 なし、動作しているようです。

答えて

1

年齢フィールドの型が整数か文字列かを確認してください。あなたの問題を解決するキーワードはmustです。

{ 
    "query": { 
     "constant_score" : { 
      "filter" : { 
       "bool" : { 
        "must" : [ 
         { "term" : { "age" : 21 } }, 
         { "term" : { "name" : "mark" } } 
        ] 
       } 
      } 
     } 
    } 
} 
+0

親切なupvote ... – harshil9968

1

Boolと "must"を使用して回答しました。

関連する問題