spdoes
(spdo es)
August 5, 2020, 2:42pm
1
if I insert this field in this order:
"name_of_field": {"first":1,"second":2,"third":3}
will it always save in the same order as I inserted ?
Based on my test, inserting multiple objects like that can make it save it different order, like:
"name_of_field": {"third":3,"first":1,"second":2}
Elasticsearch does not change the document but JSON serialisation and deserialisation does generally not guarantee that order is preserved.
spdoes
(spdo es)
August 5, 2020, 4:10pm
3
Is there any way I could enforce an order on a particular hash field ?
To do so you would need to control how your documents are serialised and deserialised which means e.g. not using scripted updates. Which client(s) are you using?
spdoes
(spdo es)
August 5, 2020, 4:21pm
5
Ruby Elasticsearch gem: https://github.com/elastic/elasticsearch-ruby
Do you want me to send the update query here ?
I will update recommended not relying on the order as it will be more resilient given that ordering is generally not guaranteed.
spdoes
(spdo es)
August 5, 2020, 4:25pm
7
Alright then,
so the best will probably be to put it under an array, like:
"name_of_field": [{"first":1},{"second":2},{"third":3}]
That sounds like a bad idea. Why do you feel you need to preserve order??
spdoes
(spdo es)
August 5, 2020, 4:44pm
9
This object will be sent through an API that will send to the browser and it needs to be displayed in a certain order
spdoes
(spdo es)
August 5, 2020, 5:30pm
10
any suggestion on a better way to deal with this ?
system
(system)
Closed
September 2, 2020, 5:33pm
12
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.