弹性搜索排序无法按预期工作

时间:2015-09-02 13:08:40

标签: sorting elasticsearch integer

我正在使用弹性搜索版本1.2.1并尝试在整数字段上对结果进行排序,但它不按照我认为必须的方式工作,并且我无法按asc或desc顺序排序。我正在使用Sense扩展的Chrome和Elastic搜索在localhost上侦听端口9200。

这是我如何定义索引:

PUT keyword_test

然后我添加了keyword_test索引的映射:

PUT /keyword_test/_mapping/keyword
{
    "keyword": {
        "properties" : {
            "id": {
                "type": "string"
            },
            "search_date": {
                "type": "string"
            },
            "keyword": {
                "type": "string",
                "index": "analyzed"
            },
            "count": {
                "type": "integer"
            }
        }
    }
}

然后我添加了不同计数的不同关键字,并尝试使用以下查询在其中搜索:

GET _search 
{
    "sort": {
        "count": {
            "order": "asc",
            "ignore_unmapped": true
        }
    },
    "query": {
        "fuzzy": {
           "keyword": "iphone"
        }
    }
}

我得到以下结果:

"hits": {
      "total": 3,
      "max_score": null,
      "hits": [
         {
            "_index": "keyword_test",
            "_type": "keyword",
            "_id": "8",
            "_score": null,
            "_source": {
               "id": 8,
               "count": 9000,
               "keyword": "iphone 5s",
               "search_date": "2015-05-05"
            },
            "sort": [
               9000
            ]
         },
         {
            "_index": "keyword_test",
            "_type": "keyword",
            "_id": "10",
            "_score": null,
            "_source": {
               "id": 10,
               "count": 9500,
               "keyword": "iphone 6 plus",
               "search_date": "2015-05-05"
            },
            "sort": [
               9500
            ]
         },
         {
            "_index": "keyword_test",
            "_type": "keyword",
            "_id": "9",
            "_score": null,
            "_source": {
               "id": 9,
               "count": 9100,
               "keyword": "iphone 6",
               "search_date": "2015-05-05"
            },
            "sort": [
               9100
            ]
         }
      ]
   }

结果应该是9000,9100,9500订单,但它是9000,9500,9100订单。如果我删除ignore_unmapped,我也会得到SearchParseException。我该怎么办?我错过了计数字段的一些映射吗?任何帮助将不胜感激,谢谢。

0 个答案:

没有答案
相关问题