Unable to use nested query on elastic search 7.2.0

Hi I Just started using Elastic search and need to come up with a solution for nested queries.
I was going through an older post but unable to get the nested query right.

Let's say I have document which has user arrays, inside that I have cars array.
I want to be able to query something like this : find documents where user.usertype="employed" and user.cars.cartype="suv".

Here is the sample mapping and queries:

PUT http://localhost:9200/t
{
"mappings": {
"properties": {
"t": {
"type": "nested",
"properties": {
"categories": {
"type": "nested",
"properties": {
"name": {
"type": "text"
},
"list": {
"type": "nested",
"properties": {
"url_site": {
"type": "text"
},
"persons": {
"type": "nested",
"properties": {
"total_customers": {
"type": "integer"
},
"total_subscribers": {
"type": "integer"
},
"details": {
"type": "nested",
"properties": {
"person_id": {
"type": "text"
},
"person_date_registration": {
"type": "date"
},
"person_date_subscription": {
"type": "date"
}
}
}
}
}
}
}
}
}
}
}
}
}
}

PUT http://localhost:9200/t/_doc/1
{
"categories" : {
"name" : "cat1",
"list" : {
"url_site" : "www.bla.org",
"persons" : {
"total_customers" : 10,
"total_subscribers" : 10,
"details" : {
"person_id" : 1
}
}
}
}
}

PUT http://localhost:9200/t/_doc/2
{
"categories" : {
"name" : "cat2",
"list" : {
"url_site" : "www.bleep.org",
"persons" : {
"total_customers" : 10,
"total_subscribers" : 10,
"details" : {
"person_id" : 2
}
}
}
}
}

PUT http://localhost:9200/t/_doc/3
{
"categories" : {
"name" : "cat3",
"list" : {
"url_site" : "www.blubb.org",
"persons" : {
"total_customers" : 10,
"total_subscribers" : 10,
"details" : {
"person_id" : 3
}
}
}
}
}

GET http://localhost:9200/t/_search
{
"query": {
"nested": {
"path": "categories",
"query": {
"nested": {
"path": "categories.list",
"query": {
"nested": {
"path": "categories.list.persons.details",
"query": {
"bool": {
"must": {
"match": {
"categories.list.persons.details.person_id": 1
}
}
}
}
}
}
}
}
}
}
}

curl -X GET "localhost:9200/t/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"nested": {
"path": "categories",
"query": {
"nested": {
"path": "categories.list",
"query": {
"nested": {
"path": "categories.list.persons.details",
"query": {
"bool": {
"must": {
"match": {
"categories.list.persons.details.person_id": 1
}
}
}
}
}
}
}
}
}
}
}
'

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.