我在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的结果更新:元数据中的River规范
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"
}
}
}
]
}
}
}
}
答案 0 :(得分:1)
我认为您的配置不符合您的要求。让我们重新开始。首先,让我们删除您的_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'