根据您要实现的目标,是:记录(
"workExperiences.isCurrentWorkplace":true和
"workExperiences.title.id": 259) 或
(
"workExperiences.isCurrentWorkplace": false和
"workExperiences.title.id":256)的位置。因此,您需要
should条款而不是
must条款:
{ "query": { "bool": { "filter": [ { "nested": { "path": "workExperiences", "query": { "bool": { "should": [ { "bool": {"must": [ { "term": { "workExperiences.isCurrentWorkplace": true } }, { "term": { "workExperiences.title.id": 259 } }] } }, { "bool": {"must": [ { "term": { "workExperiences.isCurrentWorkplace": false } }, { "term": { "workExperiences.title.id": 256 } }] } } ] } } } } ] } }}如果同一文档包含两个以上的对象(其中一个对象
workExperiences具有(
"workExperiences.isCurrentWorkplace":true and "workExperiences.title.id": 259) 和
一个对象具有())应该显示一个文档
"workExperiences.isCurrentWorkplace": false and"workExperiences.title.id": 256,则查询将为:
{ "query": { "bool": { "filter": [ { "nested": { "path": "workExperiences", "query": { "bool": { "must": [ { "term": {"workExperiences.isCurrentWorkplace": true } }, { "term": {"workExperiences.title.id": 259 } } ] } } } }, { "nested": { "path": "workExperiences", "query": { "bool": { "must": [ { "term": {"workExperiences.isCurrentWorkplace": false } }, { "term": {"workExperiences.title.id": 256 } } ] } } } } ] } }}


