我正在尝试使用mongodb- river使用以下命令在elasticsearch中为mongodb编制索引,但文档映射未生效。它仍然使用默认的分析器(标准)作为字段text
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" } } } }'
如果我按全字词搜索,但不匹配任何子字符串,则查询返回正确的结果。同样,增强因子没有显示出其效果。
我究竟做错了什么 ??
您必须首先使用索引设置(分析器)创建索引:
"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 } } }
然后,您可以为您的类型定义一个映射:
"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" } } }
只有这样,您才能创建河流:
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"} }
有帮助吗?