【问题标题】:mapping in create index in elasticsearch through mongodb river is not taking effect通过 mongodb River 在 elasticsearch 中创建索引的映射未生效
【发布时间】:2012-12-18 17:45:40
【问题描述】:

我正在尝试使用以下命令使用 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"
                }           
       }
    }
}'

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

我做错了什么??

【问题讨论】:

    标签: mongodb mapping elasticsearch lucene


    【解决方案1】:

    您必须首先使用您的index settings(分析器)创建索引:

    "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
                    }
                }
            }
    

    然后你可以define a mapping为你的类型:

    "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"} }
    

    有帮助吗?

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 2020-09-23
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多