Elasticsearch 是否保持多值字段的顺序? [英] Does Elasticsearch keep an order of multi-value fields?
问题描述
Elasticsearch 是否保持多值字段的顺序?
Does Elasticsearch keep an order of multi-value fields?
即如果我将以下值放入字段中:
I.e. if I've put following values into fields:
{
"values": ["one", "two", "three"],
"values_original": ["1", "2", "3"]
}
(鉴于未分析字段)
我能确定列表的内容总是按照我放在那里的顺序返回吗?
Can I be sure that the contents of lists will always be returned in the same order I put it there?
在上面的例子中,我想确保values"中第一个位置的one"总是对应于values_original"等中的1".
In the example above, I want to make sure that "one" on first position in "values" will always correspond to "1" in "values_original" etc.
我也可以将它保留为嵌套对象,即
I could keep it also as nested objects, i.e.
{
"values": [
{"original": "1", "new": "one"},
{"original":"2", "new":"two"},
{"original":"3","new":"three"}
]
}
但我想避免开销.
如果保证多值字段中值的顺序被保留,那么我保留两个并行多值字段的方法将起作用.
If it is guaranteed that order of values in multi-value field is preserved, then my approach of keeping two parallel multi-valued fields will work.
推荐答案
当您从 Elasticsearch 取回文档时,任何数组的顺序都与您索引文档时的顺序相同.您返回的 _source 字段包含与您编入索引的完全相同的 JSON 文档.
When you get a document back from Elasticsearch, any arrays will be in the same order as when you indexed the document. The _source field that you get back contains exactly the same JSON document that you indexed.
然而,数组作为无序的多值字段被编入索引——使其可搜索.在搜索时,您不能引用第一个元素"或最后一个元素".相反,将数组视为一袋值.
However, arrays are indexed—made searchable—as multivalue fields, which are unordered. At search time, you can’t refer to "the first element" or "the last element." Rather, think of an array as a bag of values.
所以似乎存储字段的顺序是保留的,而索引字段则不是.
So it seems that for stored fields order is preserved, for indexed fields it's not.
这篇关于Elasticsearch 是否保持多值字段的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!