Hello All,
The JSON document schema we are using involves a mix of multiple nesting levels (arrays/map within arrays/map) to depict travel itineraries. These documents are all stored in ES (Elasticsearch) within a single index. We are running into issues around trying to walk through nesting levels (finding the right path) and retrieving the correct fields. Mentioned below is an example that creates an index, mapping, inserts document and then runs a query. This is quite similar in structure to the larger travel itinerary document we are using. But we did not quite understand what ES expects for some of the queries. Here are some of the questions - 1. How is “path” in nested query determined when the document has nested and non-nested types ? 2. Can non-nested query (for non-nested fields) be used when the document mapping has nested types ? Can you give us some examples ? 3. We would like to query for an “inner nested” field but also like to know attribute of some of the outer levels. Eg. The json document has an array whose elements are also a nested array. We need to know the index of the top level array while querying the inner nested array. Test.sh (contents) #!/bin/sh #echo "\n --- delete index" curl -X DELETE 'http://localhost:9200/myindex' echo "\n --- create index and put mapping into place" curl -X POST 'http://localhost:9200/myindex/' -d '{ "mappings" : { "root" : { "type" : "nested", "include_in_parent" : "false", "properties" : { "person" : { "type" : "nested", "include_in_parent" : "false", "properties" : { "name" : {"type" : "string"}, "works" : { "type" : "nested", "include_in_parent" : false, "properties" : { "title" : {"type" : "string"}, "current" : {"type" : "boolean"}, "dummy" : {"type" : "string"}, "home": { "type": "nested", "include_in_parent" : false, "properties" : { "address" : {"type" : "string"}, "city" : {"type" : "string"} } } } } } } } }, "settings" : { "number_of_shards" : 1, "number_of_replicas" : 0 } } }' echo "\n --- index data" curl -X PUT 'http://localhost:9200/myindex/person/1' -d ' { "root" : [ { "person" : { "name" : "Lukas1", "works" : [ { "title" : "developer", "current" : true, "dummy" : "match", "home" : [ { "address" : "123 Main st", "city" : "dallas" }, { "address" : "123 Main st", "city" : "irving" } ] }, { "title" : "dad", "current" : true, "home" : [ { "address" : "123 Main st", "city" : "grapevine" } ] } ] }}, {"person" : { "name" : "Lukas2", "works" : [ { "title" : "developer", "current" : true, "dummy" : "match", "home" : [ { "address" : "123 Main st", "city" : "dallas2" }, { "address" : "123 Main st", "city" : "irving2" } ] }, { "title" : "dad", "current" : true, "home" : [ { "address" : "123 Main st", "city" : "grapevine2" } ] } ] }} ] }' #echo "\n --- optimize" #curl -X POST 'http://localhost:9200/myindex/_optimize' echo "\n --- query" curl -X GET 'http://localhost:9200/myindex/_search?pretty=true' -d ' { "query" : { "nested" : { "path" : "root.person.works.home", "query" : { "bool" : { "must" : [ { "term" : { "root.person.works.home.city" : "irving2"} } ] } } } }, "fields" : [ "root.person.name" ] }' -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/53fc3c34-fc9a-4173-a172-2987ea386bad%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
