Last active
August 29, 2015 14:13
-
-
Save nezda/6a360d44927d275178a9 to your computer and use it in GitHub Desktop.
Demonstrate that `store`'d fields with `index_name` in their mapping loaded using `fields` are returned in `hits` objects keyed by their `index_name` (e.g., "name_string", not "name" in this example).
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
#!/bin/sh | |
# Overall purpose of index_name usage here is to work around bug https://github.com/elasticsearch/elasticsearch/issues/5851 | |
echo "Remove old index..." | |
curl -XDELETE "http://localhost:9200/fml?pretty=true" | |
echo "Make index and add some data..." | |
curl -XPOST "http://localhost:9200/fml/" | |
curl -XPUT "http://localhost:9200/fml/_mapping/widget" -d ' | |
{ | |
"widget": { | |
"properties": { | |
"name": { | |
"type": "string", | |
"store": true, | |
"index_name": "name_string" | |
}, | |
"id": { | |
"type": "string", | |
"store": true | |
}, | |
"postDate": { | |
"type": "date", | |
"index_name": "postDate_date" | |
} | |
} | |
} | |
} | |
' | |
echo "Verify mappings..." | |
curl 'localhost:9200/fml/_mapping?pretty' | |
echo "Make index and add some data - default mappings are fine" | |
curl -XPOST "http://localhost:9200/fml/widget/?pretty=true" -d ' | |
{ | |
"name": "uno", | |
"id": "1", | |
"postDate" : "2009-11-15" | |
} | |
' | |
curl -XPOST "http://localhost:9200/fml/widget/?pretty=true" -d ' | |
{ | |
"name": "dos", | |
"id": "2", | |
"postDate" : "2010-11-15" | |
} | |
' | |
echo "Wait for ES to be synced (aka refresh indices)..." | |
curl -XPOST "http://localhost:9200/fml/_refresh?pretty=true" | |
echo "name_string!? (note postDate not stored, so parsed from _source and index_name not used)" | |
curl -XPOST "http://localhost:9200/fml/widget/_search?pretty=true" -d ' | |
{ | |
"query": { | |
"match_all" : { } | |
}, | |
"fields": ["name", "id", "postDate"] | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment