簡體   English   中英

Elasticsearch - Python客戶端 - 如何在多個字段上匹配?

[英]Elasticsearch - Python client - How to match on multiple fields?

我在嘗試通過Python API查詢ES服務器時匹配多個字段。 但無法弄清楚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)

任何建議將不勝感激。 沒有,似乎工作。

請確保age字段的大小為整數或字符串。 must解決您的問題的關鍵字。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM