Elasticsearch仅返回与ID数组匹配的结果

问题描述 投票:0回答:1

是否可以使用弹性搜索仅在一组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”。

有更好的方法吗?谢谢。

elasticsearch
1个回答
0
投票

对于数组搜索,您应该使用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]
                }
            }
        }
        ]
    }
},

来自documentation

默认情况下,Elasticsearch将字词查询限制为最大65,536个条款。这包括使用术语查找获取的术语。您可以使用index.max_terms_count设置更改此限制。

© www.soinside.com 2019 - 2024. All rights reserved.