Rah*_*hul 7 lucene mapping mongodb elasticsearch
我正在尝试使用mongodb-river使用以下命令在elasticsearch中索引mongodb,但文档映射未生效.它仍然使用字段的默认分析器(标准)text
Mongodb-river 该文档指定索引的创建,但没有关于如何提供自定义映射的文档.这是我试过的.是否有任何其他文档,我可以找到如何使用mongodb-river指定自定义分析器等.
curl -XPUT "localhost:9200/_river/autocompleteindex/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"host": "rahulg-dc",
"port": "27017",
"db": "qna",
"collection": "autocomplete_questions"
},
"index": {
"name": "autocompleteindex",
"type": "autocomplete_questions",
"analysis" : {
"analyzer" : {
"str_search_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase"]
},
"str_index_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase", "ngram"]
}
},
"filter" : {
"ngram" : {
"type" : "ngram",
"min_gram" : 2,
"max_gram" : 20
}
}
}
},
"autocompleteindex": {
"_boost" : {
"name" : "po",
"null_value" : 1.0
},
"properties": {
"po": {
"type": "double"
},
"text": {
"type": "string",
"boost": 3.0,
"search_analyzer" : "str_search_analyzer",
"index_analyzer" : "str_index_analyzer"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
查询返回正确的结果是我搜索完整的单词,但不匹配任何子字符串匹配.此外,提升因子没有显示其效果.
我究竟做错了什么 ??
您必须首先使用索引设置(分析器)创建索引:
"analysis" : {
"analyzer" : {
"str_search_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase"]
},
"str_index_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase", "ngram"]
}
},
"filter" : {
"ngram" : {
"type" : "ngram",
"min_gram" : 2,
"max_gram" : 20
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以为您的类型定义映射:
"autocomplete_questions": {
"_boost" : {
"name" : "po",
"null_value" : 1.0
},
"properties": {
"po": {
"type": "double"
},
"text": {
"type": "string",
"boost": 3.0,
"search_analyzer" : "str_search_analyzer",
"index_analyzer" : "str_index_analyzer"
}
}
}
Run Code Online (Sandbox Code Playgroud)
只有这样,你才能创造出河流:
curl -XPUT "localhost:9200/_river/autocompleteindex/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"host": "rahulg-dc",
"port": "27017",
"db": "qna",
"collection": "autocomplete_questions"
},
"index": {
"name": "autocompleteindex",
"type": "autocomplete_questions"} }
Run Code Online (Sandbox Code Playgroud)
有帮助吗?