我在elasticsearch中添加了“未分析的映射”选项,对结果进行排序时不起作用,这是我使用http://localhost:9200/_river/jdbc/_search
时的映射
"mappings": {
"jdbc": {
"dynamic_templates": [
{ "notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
但是,当我对结果进行排序时,它会像
http://localhost:9200/jdbc/_search?pretty=true&sort=field:asc
{
field: "McDermott Will Amery",
},
sort: [
"amery"
]
}
但是我需要从字段中的起始单词开始按A-Z顺序排列结果
更新:元数据中的河流规范
http://localhost:9200/_river/jdbc/_meta
{
"_index": "_river",
"_type": "jdbc",
"_id": "_meta",
"_version": 1,
"found": true,
"_source": {
"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": {
"jdbc": {
"dynamic_templates": [
{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
}
最佳答案
我认为您的配置对您要执行的操作不正确。让我们重新开始。首先,让我们删除您的_river
索引,然后再次从头开始创建它:
curl -XDELETE localhost:9200/_river
现在让我们再次创建它,但是这次使用correct configuration,即:
jdbc.type_mapping
字段index
和type
,将数据存储在其中这是它的样子
curl -XPUT 'localhost:9200/_river/jdbc/_meta' -d '{
"type" : "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/dbname",
"user": "user",
"password": "pass",
"sql": "SQL QUERY", <-- add your 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,
"index": "your_index", <-- add this
"type": "your_type", <-- add this
"type_mapping": { <-- add your mapping here
"your_type": { <-- match this with "type" above
"dynamic_templates": [{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}]
}
}
}
}'
然后,当您的SQL查询运行时,它将数据存储在
your_index
索引内,并使用your_type
映射类型。最后,您可以使用以下查询搜索数据:
curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&sort=field:asc'
更新
您还可以使用以下映射定义一个多字段。然后,您就可以在
not_analyzed
字段上进行排序,并在analyzed
上进行搜索:"dynamic_templates": [{
"multi": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}]
在名为
field
的字段上的查询将是curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&q=field:Luke&sort=field.raw:asc'
关于php - 未分析Elasticsearch无法在排序中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33384298/