ElasticSearch : search and return nested type -


i pretty new elasticsearch , having trouble using nested mapping / query.

i have following data structure added index :

{    "_id": "3",    "_rev": "6-e9e1bc15b39e333bb4186de05ec1b167",    "skucode": "test",    "name": "dragon vol. 1",    "pages": [        {            "id": "1",             "tags": [                {                    "name": "dragon"                },                {                    "name": "japonese"                }            ]        },        {            "id": "2",                           "tags": [                {                    "name": "tagforanotherpage"                }            ]        }    ] } 

this index mapping defined bellow :

{   "metabook" : {     "metabook" : {       "properties" : {         "_rev" : {           "type" : "string"         },         "name" : {           "type" : "string"         },         "pages" : {           "type" : "nested",           "properties" : {             "tags" : {               "properties" : {                 "name" : {                   "type" : "string"                 }               }             }           }         },         "skucode" : {           "type" : "string"         }       }     }   } } 

my goal search pages containing specific tag, , return book object filtered page list (i es return pages match given tag). (ignoring second page) :

{    "_id": "3",    "_rev": "6-e9e1bc15b39e333bb4186de05ec1b167",    "skucode": "test",    "name": "dragon vol. 1",    "pages": [        {            "id": "1",                           "tags": [                {                    "name": "dragon"                },                {                    "name": "japonese"                }            ]        }    ] } 

here query use :

{ "from": 0, "size": 10, "query" : {     "nested" : {         "path" : "pages",         "score_mode" : "avg",         "query" : {            "term" : { "tags.name" : "japonese" }        }     }   } } 

but returns empty result. doing wrong ? maybe should index "pages" directly instead of books ? missing ?

thank in advance !

sadly can't parts of document. if document matches query, whole thing back; root , nested docs. if want parts back, @ using parent/child docs.

also aren't seeing hits have small syntax error in nested query. closely @ field name:

{ "from": 0, "size": 10, "query" : {     "nested" : {         "path" : "pages",         "score_mode" : "avg",         "query" : {            "term" : { "pages.tags.name" : "japonese" }        }     }   } } 

if need parent child docs feel free ask! (there should examples if google search)

good luck!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -