天道酬勤,学无止境

elasticsearch-ruby

ElasticSearch 嵌套查询 - 排除父文档(ElasticSearch Nested Query - exclude parent document)

问题 试图排除其中一个子文档与查询不匹配的顶级文档。 对于下面的示例,我试图排除其嵌套作业之一具有current: true并与company name: Elastic匹配的所有文档company name: Elastic 。 但是由于嵌套的作业文档之一与current: false和公司name: Elastic匹配,因此返回此文档。 我正在使用嵌套查询,必须匹配公司名称和过滤器,其中 current: false。 我怎样才能使下面的文件不被退回? "name": "john doe", "jobs": [ { "title": "Vice President", "current": true, "company": { "name": "Elastic" } }, { "title": "CEO", "current": false, "company": { "name": "Elastic" } ... 回答1 这个怎么样? 请注意,我假设您有一个.keyword sub0field,它基本上与大写字母完全匹配。 如果您有不同的情况,请相应地更改字段名称: { "query": { "bool": { "must_not": [ { "nested": { "path": "jobs", "query": { "bool": { "must": [ { "term"

2021-10-21 03:25:02    分类:技术分享    elasticsearch   elasticsearch-dsl   elasticsearch-rails   elasticsearch-ruby   elasticsearch-nested

ElasticSearch Nested Query - exclude parent document

Trying to exclude top-level documents where one of the child documents doesn't match the query. For the example below, I'm trying to exclude all documents where one of its nested jobs has current: true, and matches with the company name: Elastic. But since one of the nested job documents matches with current: false and company name: Elastic, this document is returned. I am using a nested query with a must match on company name and a filter where current: false. How can I make it so that the below document is not returned? "name": "john doe", "jobs": [ { "title": "Vice President", "current"

2021-09-01 22:10:13    分类:问答    elasticsearch   elasticsearch-dsl   elasticsearch-rails   elasticsearch-ruby   elasticsearch-nested