我是在一个紧张的时间表,一个演示与弹性搜索。
我已经设置了数据库,在Logstash中使用了JDBC输入,并开始为数据库表建立索引。在某种程度上一切都很好。但部分单词搜索不起作用。在弹性文档中快速搜索建议使用nGram过滤器和词干器。因为我没有得到词干器,所以我遵循了ngram过滤器的路径。
以下是我的索引映射,
{
"settings" : {
"analysis" : {
"analyzer" : {
"translation_index_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : "standard, lowercase, translation"
},
"translation_search_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : "standard, lowercase"
}
},
"filter" : {
"translation" : {
"type" : "nGram",
"min-gram" : 3,
"max-gram" : 12
}
}
}
},
"mappings" : {
"type" : {
"properties" : {
"myType" : {
"type" : "string",
"index_analyzer" : "translation_index_analyzer",
"search_analyzer" : "translation_search_analyzer"
}
}
},
"employee" : {
"properties" : {
"birth_date": {
"type": "date",
"format" : "yyyy-MM-dd HH:mm:ss ZZ"
},
"emp_no": {
"type": "long",
"index" : "not_analyzed"
},
"first_name": {
"type": "myType"
},
"gender": {
"type": "string",
"index" : "not_analyzed"
},
"hire_date": {
"type": "date",
"format" : "yyyy-MM-dd HH:mm:ss ZZ"
},
"last_name": {
"type": "string"
}
}
}
}
我宁愿猜测类型映射,因为我迫切需要类似的东西。不确定这是否正确。
当我发这篇文章时,我得到的是错误。
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "analyzer on field [myType] must be set when search_analyzer is set"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [type]: analyzer on field [myType] must be set when search_analyzer is set",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "analyzer on field [myType] must be set when search_analyzer is set"
}
},
"status": 400
}
知道我哪里弄错了吗?
更新:我的弹性版本是2.2
从index_analyzer到分析器的更改给出了不同的错误
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "No handler for type [myType] declared on field [first_name]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [employee]: No handler for type [myType] declared on field [first_name]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "No handler for type [myType] declared on field [first_name]"
}
},
"status": 400
}
最终解决方案:,我的问题是定义一个类型。目前我将忽略这一点,但是部分搜索与以下设置一起工作
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_ngram_analyzer" : {
"tokenizer" : "my_ngram_tokenizer"
}
},
"tokenizer" : {
"my_ngram_tokenizer" : {
"type" : "nGram",
"min_gram" : "3",
"max_gram" : "12",
"token_chars": [ "letter", "digit" ]
}
}
}
},
"mappings" : {
"employee" : {
"properties" : {
"birth_date": {
"type": "date",
"format" : "yyyy-MM-dd HH:mm:ss ZZ"
},
"emp_no": {
"type": "long",
"index" : "not_analyzed"
},
"first_name": {
"type": "string",
"analyzer" : "my_ngram_analyzer",
"search_analyzer" : "my_ngram_analyzer"
},
"gender": {
"type": "string",
"index" : "not_analyzed"
},
"hire_date": {
"type": "date",
"format" : "yyyy-MM-dd HH:mm:ss ZZ"
},
"last_name": {
"type": "string",
"analyzer" : "my_ngram_analyzer",
"search_analyzer" : "my_ngram_analyzer"
}
}
}
}
}
发布于 2016-02-07 17:16:17
我猜,用analyzer来改变analyzer
编辑
我不熟悉创建类型,但您可以在相关分析器中插入first_name:
"first_name": {
"type" : "string",
"analyzer" : "translation_index_analyzer",
"search_analyzer" : "translation_search_analyzer"
},https://stackoverflow.com/questions/35256368
复制相似问题