gpt4 book ai didi

python - 如何在Python的 Elasticsearch 中搜索多个OR条件

转载 作者:行者123 更新时间:2023-12-02 23:08:48 26 4
gpt4 key购买 nike

我必须在 flex 搜索中搜索数组中的所有项目以及静态细节。

Elastics搜索索引中的字段:tech_iddetailvolumetech_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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com