4

我正在使用弹性搜索创建索引,并希望能够对“字段”country_en 进行排序(我可能想稍后添加另一个字段)。但是排序结果不正确。

降序将返回

  • 捷克共和国
  • 德国
  • 法国
  • 芬兰
  • 捷克共和国
  • 捷克共和国
  • 德国
  • 英国

当我升序排序时,顺序再次不同,但不是字母表。

我给创建索引的命令是:

curl -XPUT "localhost:9200/_river/tenders/_meta" -d '
{
  "type": "mongodb",
  "mongodb": {
    "servers": [
      { "host": "127.0.0.1", "port": 27017 }
    ],
    "options": { "secondary_read_preference": true },
    "db": "jna",
    "collection": "tenders"
  },
  "index": {
    "name": "tenders",
    "type": "string",
    "bulk": {
          "concurrent_requests": 2
    }
  },
  "mappings" : {
        "country" : {
            "_source" : { "enabled" : true },
            "properties" : {
                "country_en" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    }
}'

搜索是通过弹性搜索 PHP 库完成的。该命令是一个数组,但我使用 PHP json_encode 将其转换为 JSON。

{
  "body": {
    "query": {
      "bool": {
        "must": [
          {
            "query_string": {
              "default_field": "_all",
              "query": "Liability*"
            }
          }
        ]
      }
    },
    "from": 0,
    "size": "25",
    "sort": {
      "country_en": {
        "order": "asc",
        "ignore_unmapped": true
      }
    }
  }
}

正在索引的数据

 {
   "_id": ObjectId("53bd88db557acd276d8b4d5f"),
   "userid": null,
   "importdate": ISODate("2014-07-09T18:24:27.0Z"),
   "documentnumber": "230476-2014",
   "source": "ted",
   "typeoftender": "public",
   "categories": {
     "0": ObjectId("5210c86d9b7e7a3803000010")
  },
   "data": {
     "oj": "129",
     "ol": "de",
     "cy": "de",
     "ds": "0.00000000 1404424800",
     "dt": ISODate("2014-08-10T22:00:00.0Z"),
     "aa": NumberLong(1),
     "td": NumberLong(3),
     "nc": NumberLong(2),
     "pr": NumberLong(2),
     "ty": NumberLong(1),
     "ac": NumberLong(1),
     "heading": "01202",
     "cpv": {
         "0": "33600000"
      }
  },
   "type": "public",
   "title_en": "Pharmaceutical products",
   "category_en": "Pharmaceuticals",
   "country_en": "Germany",
}   
4

1 回答 1

1

如果您遇到需要将 ignore_unmapped 设置为 true 的问题,则意味着您遇到了映射问题。还有其他人在与 MongoDB 河的映射方面遇到了类似的问题。我建议采取以下行动:

我会将动态映射设置为 false 或将其设置为严格用于您与 River 一起使用的类型:

通过将 index.mapper.dynamic 设置为 false,可以完全禁用为未映射类型动态创建映射。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html

我还将看一下关于自定义映射和 MongoDB 河的讨论,特别是人们如何通过将动态映射设置为 false 来解决它:

https://github.com/richardwilly98/elasticsearch-river-mongodb/issues/75

于 2014-07-09T23:05:24.557 回答