0

我一直在使用 AWS Elasticsearch(6.2 版)作为后端开发一个新的搜索 API。

现在,我正在尝试支持 API 的“排序”选项。

我的映射如下(不包括不相关的字段):

{
  "properties": {
    "id": {
      "type": "text",
      "fields": {
        "raw": {
          "type":  "keyword"
        }
      }
    },
    "description": {
      "type": "text"
    },
    "materialDefinitionProperties": {
      "type": "nested",
      "properties": {
        "id": {
          "type": "text",
          "fields": {
            "raw": {
              "type":  "keyword"
            }
          },
          "analyzer": "case_sensitive_analyzer"
        },
        "value" : {
          "type": "nested",
          "properties": {
            "valueString": {
              "type": "text",
              "fields": {
                "raw": {
                  "type":  "keyword"
                }
              }
            }
          }
        }
      }
    }
  }
}

我试图允许用户按属性值(路径:)排序materialDefinitionProperties.value.valueLong.raw

请注意,它位于嵌套对象的 2 级内(materialDefinitionProperties 和 materialDefinitionProperties.value 是嵌套对象)。

要按 ID 为“PART NUMBER”的属性值对结果进行排序,我的排序请求是:

{
    "fieldName": "materialDefinitionProperties.value.valueString.raw",
    "nestedSort": {
        "path": "materialDefinitionProperties",
        "filter": {
            "fieldName": "materialDefinitionProperties.id",
            "value": "PART NUMBER",
            "slop": 0,
            "boost": 1
        },
        "nestedSort": {
            "path": "materialDefinitionProperties.value"
        }
    },
    "order": "ASC"
}

但是,当我检查响应时,“排序”字段与文档的属性值不匹配:

{
    "_index": "material-definition-index-v2",
    "_type": "default",
    "_id": "development_LITL4ZCNE",
    "_source": {
        "id": "LITL4ZCNE",
        "description": [
            "CPU, Intel, Cascade Lake, 8259CL, 24C, 210W, B1 Prod"
        ]
        "materialDefinitionProperties": [
            {
                "id": "PART NUMBER",
                "description": [],
                "value": [
                    {
                        "valueString": "202-001193-001",
                        "isOriginal": true
                    }
                ]
            }
        ]
    },
    "sort": [
        "100-000018"
    ]
},

文档的 PART NUMBER 属性是“202-001193-001”,“排序”字段显示“100-000018”,这是另一个文档的部件号。

主文档和用于排序的嵌套对象之间似乎存在不匹配。

当集群中只有少量文档时,此请求运行良好。但是,一旦我用大约 100 万条记录回填集群,就会出现症状。我也尝试过创建一个新的 ES 集群,但结果是一样的。

按其他非嵌套属性排序效果很好。

我是否误解了嵌套对象的概念,或者滥用了嵌套排序功能?

任何想法表示赞赏!

4

1 回答 1

0

这是 Elasticsearch 中的一个错误。升级到 6.4.0 解决了这个问题。

问题跟踪器:https ://github.com/elastic/elasticsearch/pull/32204

发行说明:https ://www.elastic.co/guide/en/elasticsearch/reference/current/release-notes-6.4.0.html

于 2019-02-04T19:00:10.583 回答