elasticsearch - 在 Elasticsearch-dsl 中使用多个值匹配查询
问题描述
我正在尝试编写一个查询,其中多个值应与该字段匹配。
在示例中,我尝试使用查询中的匹配字段获取所有月份的结果。我不知道的是,如何在 dsl 中编写此查询?
months = [2,3,4]
client = Elasticsearch()
s = Search(using=client, index="namco_revenuestream")
s = s.query("match", month_period=months)
解决方案
您可以使用术语查询而不是match
查询,如下所示:
{
"query": {
"terms": {
"month_period": [2,3,4]
}
}
}
编辑:使用查询match
{
"query": {
"match": {
"month_period": {
"query": "2 3 4",
"analyzer": "standard"
}
}
}
}
推荐阅读
- azure-logic-apps - 逻辑应用 - 在不同 JSON 数据源上引用和映射字段
- python - 从源窗口安装opencv
- git - git filter-branch 不删除文件
- typescript - Mocha - Chai 需要全局插件
- javascript - 从两个数组生成所有可能的字符串组合(javascript)
- python - 如何在 Optuna 中建议多元比率(有界)?
- javascript - 未处理的拒绝(TypeError):无法读取未定义的属性“当前”
- python - 如何将 JSON SList 转换为 pandas 数据框?
- java - 如何在 Spring Boot 中重新加载/重新初始化 Bean?
- javascript - Angular - 如何在模板中接收事件时添加类