【问题标题】:Elasticsearch stored_fields orderElasticsearch 存储字段顺序
【发布时间】:2021-03-09 21:13:52
【问题描述】:

我遇到了 Elasticsearch 的 stored_fields 的订单特殊性。基本上,stored_fields 不会按照我在请求中指定的顺序进行检索。例如,我使用三个字段创建以下索引,并按特定顺序请求字段:

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"]
}

在 Kibana 上运行后,检索到以下内容:

{
  "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"
          ]
        }
      }
    ]
  }
}

如您所见,stored_fields 是按 [field1, field3, field2] 的顺序检索的。这与请求 [field3, field1, field2] 的顺序不匹配。此外,它也与索引顺序 [field1, field2, field3] 不匹配。检索顺序是如何确定的? Elasticsearch 是否保证stored_fields 的顺序与请求中的字段顺序相匹配?我找不到任何关于订购的规范。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    你不能订购Json字段。这里有一个很好的解释和规范JSON order mixed up

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 2016-04-17
      • 2016-03-15
      • 2018-11-21
      相关资源
      最近更新 更多