我正在使用弹性搜索创建索引,并希望能够对“field”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",
}
答案 0 :(得分:1)
如果您遇到需要将ignore_unmapped设置为true的问题,则表示您遇到了映射问题。还有其他人与MongoDB河的映射有类似的问题。我建议采取以下行动:
我会将动态映射设置为false,或者将其设置为您对河牌使用的类型的严格:
可以完全动态创建未映射类型的映射 通过将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