I am having nested array fields, I need to query and filter the records for that. Sample payload
"test":[
"name":[
{
"name": "vanaraj",
"Age" : 26
},
{
"name": "vanaraj",
"Age" : 10
},
{
"name": "ranjit",
"Age" : 26
},
]
]
Mapping :
{
"mappings":{
"properties":{
"test":{
"properties":{
"name":{
"type":"nested",
"properties":{
"Age":{
"type":"long"
},
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
}
}
}
I am having nested array fields, I need to query and filter the records for that. Sample
"test":[
"name":[
{
"name": "vanaraj",
"Age" : 26
},
{
"name": "vanaraj",
"Age" : 10
},
{
"name": "ranjit",
"Age" : 26
},
]
]
Here how I need the query for below conditions,
- Where Name is equal to both ["vanaraj","ranjit"] to fetch
- Add condition where Age > 25 for only "vanaraj"
Remaining for ranjit it should fetch all the records, it should not the check the condition where Age >25.
I need a query like below, but it is not working.
{
"query": {
"bool": {
"filter": [
{
"nested": {
"path": "data.test.name",
"query": {
"bool": {
"filter": [
{
"terms": {
"data.test.name.name": ["vanaraj","ranjit"]
}
}
]
}
}
}
},
{
"nested": {
"path": "data.test.name",
"query": {
"bool": {
"filter": [
{
"term": {
"data.test.name.name": "vanaraj"
}
},
{
"range": {
"data.test.name.Age": {
"gt": 25
}
}
}
]
}
}
}
}
]
}
}
}