Hi -
We have indexed the document using nested mapping and the document also created in nested format in the elastic search. But while retrieving using nested query it also returns unmatched documents from both the datasets. We want only the documents which match all the 3 conditions.
Sharing the mapping, elastic data and nested query for reference.
mapping
"services": {
"type": "nested",
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"priorities": {
"type": "nested",
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"phases": {
"type": "nested",
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
Search Data
services:
{
"id": 1100,
"name": "B2B ",
"priorities": [
{
"id": 1125,
"name": "Create Test",
"phases": [
{
"id": 1128,
"name": "Acc"
}
]
},
{
"id": 1121,
"name": "Demonstrate Marketing",
"phases": [
{
"id": 1122,
"name": "Def"
},
{
"id": 1123,
"name": "App"
},
{
"id": 1124,
"name": "Acc"
}
]
}
]
}
Nested Query
{
"query" :{
"bool" : {
"must" : [
{
"nested" : {
"query" : {
"match_phrase": {
"services.id" : {
"query" : "1100",
"slop" : 0,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
"path" : "services",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0,
"inner_hits" : {
"name" : "servicesHits",
"ignore_unmapped" : false,
"from" : 0,
"size" : 3,
"version" : false,
"seq_no_primary_term" : false,
"explain" : false,
"track_scores" : false
}
}
},
{
"nested" : {
"query" : {
"match_phrase" : {
"services.priorities.id" : {
"query" : "1125",
"slop" : 0,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
"path" : "services.priorities",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"match_phrase": {
"services.priorities.phases.id" : {
"query" : "1128",
"slop" : 0,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
"path" : "services.priorities.phases",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}