简体   繁体   English

在Elasticsearch中将多个自定义分析器设置为单个字段

[英]Setting multiple custom analyzers to single field in elasticsearch

I am working in ElasticSearch environment, I have installed elasticsearch on my local machine for version 5.4.3. 我在ElasticSearch环境中工作,我已经在本地计算机上为版本5.4.3安装了elasticsearch。 I am trying to create index by defining some settings along with mappings. 我正在尝试通过定义一些设置以及映射来创建索引。 Following are my settings and mappings, 以下是我的设置和映射,

{  
   "settings":{  
      "index":{  
         "analysis":{  
            "analyzer":{  
               "index_analyzer":{  
                  "filter":[  
                     "standard",
                     "lowercase",
                     "asciifolding"
                  ],
                  "tokenizer":"standard"
               },
               "autocomplete":{  
                  "type":"custom",
                  "tokenizer":"standard",
                  "filter":[  
                     "lowercase",
                     "autocomplete_filter"
                  ]
               },
               "search_analyzer":{  
                  "filter":[  
                     "standard",
                     "lowercase",
                     "asciifolding"
                  ],
                  "tokenizer":"standard"
               },
               "sortable":{  
                  "filter":"lowercaseFilter",
                  "tokenizer":"keyword",
                  "type":"custom"
               }
            },
            "filter":{  
               "lowercaseFilter":{  
                  "type":"lowercase"
               },
               "autocomplete_filter":{  
                  "type":"edge_ngram",
                  "min_gram":1,
                  "max_gram":20
               }
            },
            "tokenizer":{  
               "keyword":{  
                  "type":"keyword"
               }
            }
         }
      }
   }
}

this is my mappings, 这是我的映射

{  
   "geo_data":{  
      "_all":{  
         "enabled":true,
         "index_analyzer":"index_analyzer",
         "search_analyzer":"search_analyzer"
      },
      "properties":{  
         "subscriber_level":{  
            "analyzer":"index_analyzer,search_analyzer,autocomplete_analyzer",
            "type":"text"
         },
         "att_id":{  
            "analyzer":"index_analyzer,search_analyzer,autocomplete_analyzer",
            "type":"text"
         },
         "id":{  
            "include_in_all":false,
            "type":"text"
         },
         "name":{  
            "analyzer":"index_analyzer,search_analyzer,autocomplete_analyzer",
            "type":"text"
         },
         "state_name":{  
            "analyzer":"index_analyzer,search_analyzer,autocomplete_analyzer",
            "type":"text"
         }
      }
   }
}

What I want to achieve is, I want to apply all custom analyzers to a single field. 我想要实现的是,我想将所有自定义分析器应用于单个字段。 But above mappings on fields for analyzers giving following exception, 但以上针对分析器的字段映射给出了以下异常,

{  
   "error":{  
      "root_cause":[  
         {  
            "type":"mapper_parsing_exception",
            "reason":"analyzer [index_analyzer,search_analyzer,autocomplete_analyzer] not found for field [subscriber_level]"
         }
      ],
      "type":"mapper_parsing_exception",
      "reason":"analyzer [index_analyzer,search_analyzer,autocomplete_analyzer] not found for field [subscriber_level]"
   },
   "status":400
}

Please anybody can help me to fix this issue, struggling on it. 请任何人都可以帮助我解决这个问题,努力解决。

you look to tokenize a same field with multiple analyzer. 您希望使用多个分析器标记同一字段。 You can use multi-fields and apply different analyzer to each type inside multi-fields. 您可以使用多字段并将不同的分析器应用于多字段中的每种类型。

Also following this github issue , configuration for _all field are changed for 5.4. 同样在此github问题之后 ,_all字段的配置已更改为5.4。 If your indexed is already exist, 如果您已建立索引,

PUT some_index/_mappings/type_name
{
            "_all": {
                "enabled": true,
                "type": "text",
                "analyzer": "index_analyzer"
            },
            "properties": {
                "subscriber_level": {
                    "type": "keyword",
                    "fields": {
                        "index_analyzed": {
                            "type": "text",
                            "analyzer": "index_analyzer"
                        },
                        "search_analyzed": {
                            "type": "text",
                            "analyzer": "search_analyzer"
                        },
                        "autocomplete_analyzed": {
                            "type": "text",
                            "analyzer": "autocomplete"
                        }
                    }
                },
                "att_id": {
                    "type": "keyword",
                    "fields": {
                        "index_analyzed": {
                            "type": "text",
                            "analyzer": "index_analyzer"
                        },
                        "search_analyzed": {
                            "type": "text",
                            "analyzer": "search_analyzer"
                        },
                        "autocomplete_analyzed": {
                            "type": "text",
                            "analyzer": "autocomplete"
                        }
                    }
                },
                "id": {
                    "include_in_all": false,
                    "type": "text"
                },
                "name": {
                    "type": "keyword",
                    "fields": {
                        "index_analyzed": {
                            "type": "text",
                            "analyzer": "index_analyzer"
                        },
                        "search_analyzed": {
                            "type": "text",
                            "analyzer": "search_analyzer"
                        },
                        "autocomplete_analyzed": {
                            "type": "text",
                            "analyzer": "autocomplete"
                        }
                    }
                },
                "state_name": {
                    "type": "keyword",
                    "fields": {
                        "index_analyzed": {
                            "type": "text",
                            "analyzer": "index_analyzer"
                        },
                        "search_analyzed": {
                            "type": "text",
                            "analyzer": "search_analyzer"
                        },
                        "autocomplete_analyzed": {
                            "type": "text",
                            "analyzer": "autocomplete"
                        }
                    }
            }
    },
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "index_analyzer": {
                        "filter": [
                            "standard",
                            "lowercase",
                            "asciifolding"
                        ],
                        "tokenizer": "standard"
                    },
                    "autocomplete": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "autocomplete_filter"
                        ]
                    },
                    "search_analyzer": {
                        "filter": [
                            "standard",
                            "lowercase",
                            "asciifolding"
                        ],
                        "tokenizer": "standard"
                    },
                    "sortable": {
                        "filter": "lowercaseFilter",
                        "tokenizer": "keyword",
                        "type": "custom"
                    }
                },
                "filter": {
                    "lowercaseFilter": {
                        "type": "lowercase"
                    },
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 20
                    }
                },
                "tokenizer": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

Now you use any of the analyzed field for query like following 现在,您可以使用任何已分析的字段进行查询,如下所示

POST some_index/_search
{
  "query": {
    "term": {
      "state_name.index_analyzed": {
        "value": "VALUE"
      }
    }
  }
}

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Django中为单个字段实现多个请求值 - how to implement multiple request values for single field in django 在Windows OS上设置elasticsearch? - Setting up elasticsearch on windows os? 自定义分析器在Elasticsearch中不起作用 - Custom analyzer not working in elasticsearch Elasticsearch 6创建新字段需要数据类型,但“在6.x中创建的索引仅允许每个索引使用单一类型” - Elasticsearch 6 create new field requires data type but “Indices created in 6.x only allow a single-type per index” 有什么方法可以使用curl查询多个文档以从_source提取字段值来查询elasticsearch吗? - Is there any way to query elasticsearch using curl for multiple documents to extract field values from _source? 如何使用elasticsearch python中的特定字段名称从多个索引中删除文档? - How to delete documents from multiple indices using particular field name in elasticsearch python? 范围查询不支持Elasticsearch字段 - Elasticsearch field not supported in range query elasticsearch 一个查询中的多个通配符 - Multiple wildcards in one query in elasticsearch 映射索引Elasticsearch时间戳定制 - Mapping index Elasticsearch timestamp custom Elasticsearch 索引时间戳字段失败 - Elasticsearch indexing timestamp-field fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM