简体   繁体   English

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

[英]ElasticSearch - filtered query with multiple clauses ES 5

I'm currently trying to create a query that matches multiple fields in a filter differently after switching to elastic search 5, but they do not seem to be working. 我目前正在尝试创建一个查询,该查询在切换到弹性搜索5后以不同的方式匹配过滤器中的多个字段,但是它们似乎无法正常工作。 This is what I think think the query should be: 这就是我认为查询应为的内容:

        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} },
                        ]
                    }}
                ]
            }
        }

In this case, the results must match the non-analyzed item Id and group Id. 在这种情况下,结果必须与未分析的项目ID和组ID相匹配。 In the previous code, elastic search 1.5 was used and the matching was done by a collection of 'and' and 'or' placed within the filter. 在之前的代码中,使用了弹性搜索1.5,并且通过在过滤器中放置“ and”和“ or”的集合来进行匹配。 This does not work anymore it seems. 看来这不再起作用了。

I also want to make it so the query is able to get anyone with one of the passed group Id (rather than all of them). 我也想这样做,以便查询能够获取具有传递的组ID之一(而不是全部)的任何人。 I tried to do that in the second bool query of the filter. 我试图在过滤器的第二个布尔查询中做到这一点。

Ideally, I want a query that has the match 'athing', belongs to the owner ID 123 and the item ID of 3453 that is present in either group ID 123565 or 5555. 理想情况下,我想要一个具有匹配“ athing”的查询,该查询属于所有者ID 123和组ID 123565或5555中存在的项目ID 3453。

try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM