Last active
August 29, 2015 13:56
-
-
Save johtani/9183848 to your computer and use it in GitHub Desktop.
Different behavior fields in nested object. If store="yes", Elasticsearch does not return stored data. If store="no", Elasticsearch return stored data from _source.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"took": 3, | |
"timed_out": false, | |
"_shards": { | |
"total": 5, | |
"successful": 5, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": 1, | |
"max_score": 0.625, | |
"hits": [ | |
{ | |
"_index": "library", | |
"_type": "books", | |
"_id": "1", | |
"_score": 0.625, | |
"_source": { | |
"book": { | |
"title": "ElasticSearch Server", | |
"contents": "Learn the basics of ElasticSearch" | |
} | |
}, | |
"fields": { | |
"book.title": [ | |
"ElasticSearch Server" | |
] | |
} | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT /library | |
POST /library/books/_mapping | |
{ | |
"books" : { | |
"properties": { | |
"book" : { | |
"type": "nested", | |
"properties": { | |
"title" : { "type": "string", "analyzer": "standard", "store": "no"}, | |
"contents" : {"type": "string", "analyzer": "standard", "store": "yes"} | |
} | |
} | |
} | |
} | |
} | |
PUT /library/books/1 | |
{ | |
"book" : { | |
"title" : "ElasticSearch Server", | |
"contents" : "Learn the basics of ElasticSearch" | |
} | |
} | |
GET /library/books/_search | |
{ | |
"_source" : ["book.title","book.contents"], | |
"fields": [ | |
"book.title", | |
"book.contents" | |
], | |
"query": { | |
"nested": { | |
"path": "book", | |
"query": { | |
"query_string" : { | |
"query" : "ElasticSearch", | |
"fields" : ["book.title", "book.contents"] | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment