【发布时间】:2017-11-02 00:22:19
【问题描述】:
我有一个大型 ES 索引,其中包含动态创建的“关键字”字段。我需要对这些启用不区分大小写的搜索。我知道分析器不适用于关键字字段,而规范器将用于它:https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-normalizers.html
有没有办法将规范化器动态添加到字段/映射?我可以通过关闭索引、添加分析器并重新打开索引来将分析器添加到现有文本字段。在添加规范化器时,这似乎不适用于现有索引。除了创建另一个索引来重新索引所有数据之外,还有其他方法吗?
这是我的步骤: 使用小写规范器创建测试索引:
curl -XPUT localhost:9200/ganesh_index/ -d '
{
"settings": {
"analysis": {
"normalizer": {
"useLowercase": {
"type": "custom",
"filter": [ "lowercase" ]
}
}
}
},
"mappings":{
"ganesh_type":{
"properties":{
"title":{
"normalizer":"useLowercase",
"type":"keyword"
}
}
}
}
}'
现在,我可以根据需要插入和查询:
curl -X PUT localhost:9200/ganesh_index/ganesh_type/1 -d '{"title":"ThisFox.StatusCode1"}'
curl -X PUT localhost:9200/ganesh_index/ganesh_type/2 -d '{"title":"ThisFox.StatusCode2"}'
curl -X POST 'localhost:9200/ganesh_index/_search?pretty' -d '{"query": {"regexp":{"title": "this.*code1"}}}'
{
"took" : 24,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "ganesh_index",
"_type" : "ganesh_type",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"title" : "ThisFox.StatusCode1"
}
}
]
}
}
但是,如果我的索引已经存在,像这样:
curl -X PUT localhost:9200/ganesh_index -d '
{
"settings": {
"index": {
"number_of_shards": 2,
"number_of_replicas": 2
}
}
}'
我插入了记录,以后无法添加规范器。
curl -XPUT localhost:9200/ganesh_index/?pretty -d '
> {
> "settings": {
> "analysis": {
> "normalizer": {
> "useLowercase": {
> "type": "custom",
> "filter": [ "lowercase" ]
> }
> }
> }
> },
> "mappings":{
> "ganesh_type":{
> "properties":{
> "title":{
> "normalizer":"useLowercase",
> "type":"keyword"
> }
> }
> }
> }
> }'
{
"error" : {
"root_cause" : [
{
"type" : "index_already_exists_exception",
"reason" : "index [ganesh_index/mg5TckzaR5KZDE-FphTeDg] already exists",
"index_uuid" : "mg5TckzaR5KZDE-FphTeDg",
"index" : "ganesh_index"
}
],
"type" : "index_already_exists_exception",
"reason" : "index [ganesh_index/mg5TckzaR5KZDE-FphTeDg] already exists",
"index_uuid" : "mg5TckzaR5KZDE-FphTeDg",
"index" : "ganesh_index"
},
"status" : 400
}
有没有办法为现有索引添加规范器(在关键字字段上)?
【问题讨论】:
标签: elasticsearch