[英]Setting multiple custom analyzers to single field in elasticsearch
我在ElasticSearch環境中工作,我已經在本地計算機上為版本5.4.3安裝了elasticsearch。 我正在嘗試通過定義一些設置以及映射來創建索引。 以下是我的設置和映射,
{
"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"
}
}
}
}
}
}
這是我的映射
{
"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"
}
}
}
}
我想要實現的是,我想將所有自定義分析器應用於單個字段。 但以上針對分析器的字段映射給出了以下異常,
{
"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
}
請任何人都可以幫助我解決這個問題,努力解決。
您希望使用多個分析器標記同一字段。 您可以使用多字段並將不同的分析器應用於多字段中的每種類型。
同樣在此github問題之后 ,_all字段的配置已更改為5.4。 如果您已建立索引,
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"
}
}
}
}
}
}
現在,您可以使用任何已分析的字段進行查詢,如下所示
POST some_index/_search
{
"query": {
"term": {
"state_name.index_analyzed": {
"value": "VALUE"
}
}
}
}
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.