通过mongodb river在elasticsearch中创建索引中的映射未生效 [英] mapping in create index in elasticsearch through mongodb river is not taking effect

查看:32
本文介绍了通过mongodb river在elasticsearch中创建索引中的映射未生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 mongodb-river 使用以下命令在 elasticsearch 中索引 mongodb,但文档映射未生效.它仍然使用字段 text

I am trying to index mongodb in elasticsearch using mongodb-river using the following command but the document mapping is not taking effect. It is still using the default analyzer(standard) for field text

Mongodb-river该文档指定了索引的创建,但没有关于如何提供自定义映射的文档.这是我尝试过的.是否有任何其他文档可以找到如何在使用 mongodb-river 时指定自定义分析器等.

Mongodb-river The document specifies the creation of index but there is no documentation on how to provide custom mapping. This is what I tried. Is there any other documentation where I can find how to specify custom analyzers etc in using 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"
                }           
       }
    }
}'

查询返回正确的结果是我按完整词搜索但不匹配任何子字符串匹配.此外,升压因子没有显示其效果.

The query returns proper results is I search by full words but does not match any substring match. Also, the boost factor is not showing its effect.

我做错了什么??

推荐答案

您必须首先使用 索引设置(分析器):

You have to create first your index with your index settings (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"
            }           
   }
}

只有这样,你才能创造河流:

And only then, you can create the 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"} }

有帮助吗?

这篇关于通过mongodb river在elasticsearch中创建索引中的映射未生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆