ElasticSearch - 包含多个子句的过滤查询 ES 5



切换到弹性搜索 5 后,我目前正在尝试创建一个以不同方式匹配过滤器中多个字段的查询,但它们似乎不起作用。这是我认为查询应该是:

        query: {
            bool: {
                must: [{ match: { name: 'athing' }}],
                filter: [
                    { bool: {
                        must: [
                            { term: { ownerId: 123} },
                            { term: { itemId: 3453} },
                        ]
                    }},
                    { bool: {
                        minimum_should_match: 1,
                        must: [
                            { term: { groupId: 123565} },
                            { term: { groupId: 5555} },
                        ]
                    }}
                ]
            }
        }

在这种情况下,结果必须与未分析的项目 ID 和组 ID 匹配。在前面的代码中,使用了弹性搜索 1.5,匹配是通过放置在筛选器中的"and"和"or"集合完成的。这似乎不再起作用了。

我还想这样做,以便查询能够获得具有传递的组 ID 之一(而不是所有组 ID(的任何人。我试图在过滤器的第二个布尔查询中执行此操作。

理想情况下,我想要一个具有匹配"athing"的查询,属于所有者 ID 123 和组 ID 123565 或 5555 中存在的项目 ID 3453。

尝试

bool:
  must: [ term: ownerId, term: itemId]
  should: [ term: groupId, term: groupId ] 
  minimum_should_match: 1

最新更新