是否可以使用弹性搜索仅在一组roomIds内进行查询?
我尝试使用bool,应该:
query: {
bool: {
must: [
{
multi_match: {
operator: 'and',
query: keyword,
fields: ['content'],
type: 'most_fields'
}
},
{ term: { users: caller } },
{
bool: {
should:
term: {
room: [list of roomIds]
}
}
}
]
}
},
它可以工作,但是当我有超过1k个roomId时,我会收到“ search_phase_execution_exception”。
有更好的方法吗?谢谢。
对于数组搜索,您应该使用terms查询而不是term
query: {
bool: {
must: [
{
multi_match: {
operator: 'and',
query: keyword,
fields: ['content'],
type: 'most_fields'
}
},
{ term: { users: caller } },
{
bool: {
should:
terms: {
room: [list of roomIds]
}
}
}
]
}
},
默认情况下,Elasticsearch将字词查询限制为最大65,536个条款。这包括使用术语查找获取的术语。您可以使用index.max_terms_count设置更改此限制。