如何在多个字段上匹配Python客户端?

2024-05-20 19:36:09 发布

您现在位置:Python中文网/ 问答频道 /正文

当通过pythonapi查询ES服务器时,我试图在多个字段上进行匹配。但无法理解Python中的语法:

我试过了

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

以及

^{pr2}$

以及

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

如有任何建议,将不胜感激。 没有,似乎在工作。在


Tags: nameagesearchindexdocestypematch
1条回答
网友
1楼 · 发布于 2024-05-20 19:36:09

请确保年龄字段的类型为整数或字符串。解决问题的关键字是must。在

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

相关问题 更多 >