作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须在 flex 搜索中搜索数组中的所有项目以及静态细节。
Elastics搜索索引中的字段:tech_id
,detail
,volume
tech_ids = ['qwe1', 'qwe2', 'qwe3', 'qwe4', 'qwe5', 'qwe6', 'qwe7']
数组中的tech_id数量可以不同。
现在,我必须在tech_id和detail的组合中进行搜索,其中tech_id有所不同,而detail保持不变。此组合是or
组合。最后,我希望搜索具有提供的tech_id和静态详细信息。
tech_ids = ['qwe1', 'qwe2', 'qwe3', 'qwe4', 'qwe5', 'qwe6', 'qwe7']
"query": {
"bool": {
"must": [
{
"match": {
"detail": "calci"
}
},
{
"match_phrase": {
"tech_id": tech_ids[0]
}
}]
}
最佳答案
我认为,您追求的是必须在 bool(boolean) 值内进行 bool(boolean) 值运算:
{
"query": {
"bool": {
"must": [
{
"match": {
"detail": "calci"
}
},
{
"bool": {
"should":
[{
"match_phrase": { "tech_id": tid }
} for tid in tech_ids]
}
}
]
}
}
}
关于python - 如何在Python的 Elasticsearch 中搜索多个OR条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446030/
我是一名优秀的程序员,十分优秀!