Elasticsearch 找不到分析器但它创建索引没有任何错误
Elasticsearch Failed to find analyzer but it creates index without any error
这是我测试时的索引设置 json
http://localhost:9200/myIndex/_analyze?text="testing the analyzer"&分析仪=nGram_analyzer
我收到以下异常。
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[Infectia][127.0.0.1:9300][indices:admin/analyze[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to find analyzer [nGram_analyzer]"
},
"status": 400
}
索引设置
{
"myIndex": {
"mappings": {
"practices": {
"properties": {
"practiceCity": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practiceId": {
"type": "long",
"index":"not_analyzed"
},
"practiceName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practicePhone": {
"type": "long",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practiceService": {
"type": "string",
"boost": 5,
"index":"not_analyzed"
}
}
},
"users": {
"_all": {
"analyzer": "nGram_analyzer"
},
"properties": {
"userCityId": {
"type": "long",
"index":"not_analyzed",
"analyzer": "nGram_analyzer"
},
"userCityName": {
"type": "string",
"index":"not_analyzed"
},
"userEmail": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userFirstName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userId": {
"type": "long"
},
"userLastName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userMobile": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userSpecialization": {
"type": "string",
"boost": 5,
"index":"not_analyzed"
}
}
}
},
"settings": {
"index": {
"analysis": {
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"nGram_filter"
]
}
},
"filter": {
"nGram_filter": {
"max_gram": "20",
"type": "edgeNGram",
"min_gram": "3",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
}
},
"number_of_replicas": "1",
"number_of_shards": "5"
}
}
}
}
我正在研究自动完成功能,我的索引看起来不错吗?
对性能改进有什么建议吗?
您需要像这样更改 settings
部分:(即 analysis
直接在 settings
下,而不是在 index
中)
PUT myindex
{
"mappings": {
"practices": {
"properties": {
"practiceCity": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"practiceId": {
"type": "long",
"index": "not_analyzed"
},
"practiceName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"practicePhone": {
"type": "long",
"boost": 10
},
"practiceService": {
"type": "string",
"boost": 5,
"index": "not_analyzed"
}
}
},
"users": {
"properties": {
"userCityId": {
"type": "long"
},
"userCityName": {
"type": "string",
"index": "not_analyzed"
},
"userEmail": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userFirstName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userId": {
"type": "long"
},
"userLastName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userMobile": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userSpecialization": {
"type": "string",
"boost": 5,
"index": "not_analyzed"
}
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "5"
},
"analysis": {
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"nGram_filter"
]
}
},
"filter": {
"nGram_filter": {
"max_gram": "20",
"type": "edgeNGram",
"min_gram": "3",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
}
}
}
}
这是我测试时的索引设置 json http://localhost:9200/myIndex/_analyze?text="testing the analyzer"&分析仪=nGram_analyzer 我收到以下异常。
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[Infectia][127.0.0.1:9300][indices:admin/analyze[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to find analyzer [nGram_analyzer]"
},
"status": 400
}
索引设置
{
"myIndex": {
"mappings": {
"practices": {
"properties": {
"practiceCity": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practiceId": {
"type": "long",
"index":"not_analyzed"
},
"practiceName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practicePhone": {
"type": "long",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"practiceService": {
"type": "string",
"boost": 5,
"index":"not_analyzed"
}
}
},
"users": {
"_all": {
"analyzer": "nGram_analyzer"
},
"properties": {
"userCityId": {
"type": "long",
"index":"not_analyzed",
"analyzer": "nGram_analyzer"
},
"userCityName": {
"type": "string",
"index":"not_analyzed"
},
"userEmail": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userFirstName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userId": {
"type": "long"
},
"userLastName": {
"type": "string",
"boost": 10,
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userMobile": {
"type": "string",
"index":"analyzed",
"analyzer": "nGram_analyzer"
},
"userSpecialization": {
"type": "string",
"boost": 5,
"index":"not_analyzed"
}
}
}
},
"settings": {
"index": {
"analysis": {
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"nGram_filter"
]
}
},
"filter": {
"nGram_filter": {
"max_gram": "20",
"type": "edgeNGram",
"min_gram": "3",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
}
},
"number_of_replicas": "1",
"number_of_shards": "5"
}
}
}
}
我正在研究自动完成功能,我的索引看起来不错吗? 对性能改进有什么建议吗?
您需要像这样更改 settings
部分:(即 analysis
直接在 settings
下,而不是在 index
中)
PUT myindex
{
"mappings": {
"practices": {
"properties": {
"practiceCity": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"practiceId": {
"type": "long",
"index": "not_analyzed"
},
"practiceName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"practicePhone": {
"type": "long",
"boost": 10
},
"practiceService": {
"type": "string",
"boost": 5,
"index": "not_analyzed"
}
}
},
"users": {
"properties": {
"userCityId": {
"type": "long"
},
"userCityName": {
"type": "string",
"index": "not_analyzed"
},
"userEmail": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userFirstName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userId": {
"type": "long"
},
"userLastName": {
"type": "string",
"boost": 10,
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userMobile": {
"type": "string",
"index": "analyzed",
"analyzer": "nGram_analyzer"
},
"userSpecialization": {
"type": "string",
"boost": 5,
"index": "not_analyzed"
}
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "5"
},
"analysis": {
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"nGram_filter"
]
}
},
"filter": {
"nGram_filter": {
"max_gram": "20",
"type": "edgeNGram",
"min_gram": "3",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
}
}
}
}