我必须在弹性搜索中搜索数组中的所有项目以及静态细节。
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]
}
}]
}
答案 0 :(得分:1)
我想,您追求的是必须在布尔值内进行布尔值:
{
"query": {
"bool": {
"must": [
{
"match": {
"detail": "calci"
}
},
{
"bool": {
"should":
[{
"match_phrase": { "tech_id": tid }
} for tid in tech_ids]
}
}
]
}
}
}