I've run into an order peculiarity with the stored_fields of Elasticsearch. Basically, the stored_fields are not retrieved in the order I specify in the request. As an example, I create the following index with three fields and request the fields in a specific order:
PUT /test_field_order
{
"mappings": {
"properties": {
"field1": { "type": "text", "store": true},
"field2": { "type": "text", "store": true},
"field3": { "type": "text", "store": true}
}
}
}
PUT /test_field_order/_doc/1
{
"field1": "field1",
"field2": "field2",
"field3": "field3"
}
GET test_field_order/_search
{
"query": {
"match": {
"_id": 1
}
},
"stored_fields": ["field3", "field1", "field2"]
}
After running this on Kibana, the following is retrieved:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test_field_order",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"fields" : {
"field1" : [
"field1"
],
"field3" : [
"field3"
],
"field2" : [
"field2"
]
}
}
]
}
}
As you can see, the stored_fields are retrieved in the order [field1, field3, field2]. This doesn't match with the order of the request [field3, field1, field2]. Furthermore, it doesn't match with the index order [field1, field2, field3] either. How is the retrieve order determined? Does Elasticsearch guarantee that the order of stored_fields match the order of fields in the request? I couldn't find any specification about the ordering.