Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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).
#!/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