elasticsearch - 排序在 Elasticsearch 中不起作用

标签 elasticsearch elasticsearch-plugin elasticsearch-mongo-river

我正在创建一个带有 Elasticsearch 的索引,并希望能够对“字段” 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" }
                }
            }
        }
    }'
    

    搜索是通过 Elasticsearch 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",
    }   
    

    最佳答案

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

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

    The dynamic creation of mappings for unmapped types can be completely disabled by setting index.mapper.dynamic to 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

    关于elasticsearch - 排序在 Elasticsearch 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24661507/

    相关文章:

    elasticsearch - 试图在elasticsearch中添加映射

    mongodb - elasticsearch:_id字段的特殊行为?

    Elasticsearch |使用包含术语和术语的列表查询文档不起作用

    elasticsearch - 如果同义词是多词,Elasticsearch如何使用同义词标记过滤器?

    elasticsearch - ElasticSearch mapper-annotated-text插件:仅搜索带注释的 token

    elasticsearch - Elastic Search Head插件-删除索引中的所有记录

    mongodb - Elasticsearch 按数组字段大小过滤

    Elasticsearch:访问由 filebeat 创建的多个索引

    elasticsearch - 使用非必填字段创建Elasticsearch索引进行排序

    grails - 在grails中安装elasticsearch插件时出现NoNodeAvailableException