ElasticSearch - 带有多个子句的过滤查询ES 5

时间:2017-06-29 23:43:14

标签: elasticsearch

我目前正在尝试创建一个在切换到弹性搜索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,匹配是由'和'和'或'放在过滤器内。这似乎不再起作用了。

我也希望这样做,以便查询能够让任何人拥有一个传递的组ID(而不是所有组)。我尝试在过滤器的第二个bool查询中执行此操作。

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

1 个答案:

答案 0 :(得分:1)

尝试

bool:
  must: [ term: ownerId, term: itemId]
  should: [ term: groupId, term: groupId ] 
  minimum_should_match: 1
相关问题