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_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屋!