Elasticsearch仅按字母排序,不按数字排序
我在PHP中遇到排序问题,以下是我的映射:Elasticsearch仅按字母排序,不按数字排序,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我在PHP中遇到排序问题,以下是我的映射: { "jdbc": { "mappings": { "jdbc": { "properties": { "admitted_date": { "type": "date", "format&quo
{
"jdbc": {
"mappings": {
"jdbc": {
"properties": {
"admitted_date": {
"type": "date",
"format": "dateOptionalTime"
},
"et_tax": {
"type": "string"
},
"jt_tax": {
"type": "string"
},
"loc_cityname": {
"type": "string"
},
"location_countryname": {
"type": "string"
},
"location_primary": {
"type": "string"
},
"pd_firstName": {
"type": "string"
}
}
}
}
}
}
当我使用“按排序对结果排序”时,它将使用字母数字对结果排序,它将首先使用数字加载结果。我只需要订购结果的起始字母。现在它的顺序如下:
"pd_lawFirmName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
http://localhost:9200/jdbc/_search?pretty=true&sort=pd_lawFirmName:asc
{
"type" : "jdbc",
"jdbc" : {
"driver" : "com.mysql.jdbc.Driver",
"url" : "jdbc:mysql://localhost:3306/dbname",
"user" : "user",
"password" : "pass",
"sql" : "SQL QUERY",
"poll" : "24h",
"strategy" : "simple",
"scale" : 0,
"autocommit" : true,
"bulk_size" : 5000,
"max_bulk_requests" : 30,
"bulk_flush_interval" : "5s",
"fetchsize" : 100,
"max_rows" : 149669,
"max_retries" : 3,
"max_retries_wait" : "10s",
"locale" : "in",
"digesting" : true,
"mappings": {
"sorting": {
"properties": {
"pd_lawFirmName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
这是因为Elasticsearch将使用默认分析器标记文本,该分析器是
标准的
。例如,McDermott Will Amery
的索引如下:
"amery",
"mcdermott",
"will"
如果您想这样排序,我建议您更改pd\u lawFirmName
的映射,如下所示:
"pd_lawFirmName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
并按raw
子字段进行排序:
http://localhost:9200/jdbc/_search?pretty=true&sort=pd_lawFirmName.raw:asc
您是否查看了“是”,但它将结果从最后一个单词排序,下面是示例
pd\u lawFirmName:“McDermott Will Amery”,
排序:[“Amery”]
。但是第一个字母是M
当我使用URL错误时,我得到了以下错误:“SearchPhaseExecutionException[未能执行阶段[query],所有碎片都失败;shardFailures{[U8fk4Ih3SOGSsl0p_aY8ww][jdbc][0]:SearchParseException[[jdbc][0]:from[-1],size[-1]:解析失败[未能解析源[{“sort”:[{“pd_lawFirmName.raw”:{”顺序“:“asc”}}]];嵌套:SearchParseException[[jdbc][0]:from[-1],size[-1]:解析失败[pd_lawFirmName.raw]未找到映射以便进行排序]];}
您是否按照我的建议更改了映射?是的,这是我的查询{……,“映射”:{“排序”:{“属性”:{“pd_lawFirmName”:{“类型”:“字符串”,“字段”:{”原始“{”类型“:”字符串“,”索引“:”未分析“}}}}}
您的初始映射-jdbc
-看起来与您现在提供的完全不同。请更新您的帖子,并提供您现在拥有的精确映射和您测试的精确查询。我指的是Elasticsearch中的实际映射:GET/jdbc/\u-mapping
。