I have a complicated mapping where multiple levels of nested objects contain information e.g. level3_attr1 and level4_attr1 I want to search.
mappings : {
mytype: {
properties: {
level1tag: {
properties: {
level2tag: {
type: "nested",
properties: {
...
level3tag: {
type: "nested",
properties: {
...
level3_attr1: {
type: "text",
fields: { keyword: { type: "keyword", ignore_above: 256 } }
}
level4tag: {
type: "nested",
properties: {
...
level4_attr1: {
type: "text",
fields: { keyword: { type: "keyword", ignore_above: 256 } }
}
}
}// end level4tag
...
}
}// level3tag
}
}// level2tag
}
}// level1tag
}
}
}
Now I want to achieve the effect like SQL's ... where level3_attr1 = 'value A' and level4_attr1 = 'value B' ...
through search API. But specifying query as below
{
"query": {
"bool" : {
"must": [
{
"nested": {
"path": "level1tag.leve2tag.level3tag.level4tag",
"query": {
"bool": {
"must": [
{
"term": {
"level1tag.level2tag.level3tag.level4tag.level4_attr1.keyword": "value A"
}
}
]
}
}
}
},
{
"nested": {
"path": "level1.level2.level3",
"query": {
"bool": {
"must": [
{
"term" : {
"level1tag.level2tag.level3tag.level3_attr1.keyword": "value B"
}
}
]
}
}
}
}
]
}
}
}
returns the result with effect like or (i.e. level3_attr1 = 'value A' or level4_attr1 = 'value B') where multiple docs having one of the attributes match returned.
So my question is how can I achieve the effect like and when using search API in a multiple nested object mapping index?