mongodb - 通过 mongodb River 在 elasticsearch 中创建索引的映射未生效

标签 mongodb mapping elasticsearch lucene

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

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

我做错了什么??

最佳答案

您必须首先使用您的 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"} }

有帮助吗?

关于mongodb - 通过 mongodb River 在 elasticsearch 中创建索引的映射未生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14154575/

相关文章:

.net - 多对多映射中的父键列类型更改

templates - 尽管禁用了dynamic_mapping,但Logstash仍继续创建字段

javascript - MongoDB 插入不重复

javascript - 异步/等待 - Node - Express - Mongo

php - 为什么 MongoDB 在简单插入后崩溃?

javascript - 如何在javascript中对两个对象和数组进行映射

symfony - Elasticsearch替换特殊字符

elasticsearch - 在Elasticsearch 7.6中用空格突出显示单词

elasticsearch - 使用http_poll,logstash不会在kibana dahboard中创建索引模式。错误-LogStash::ConfigurationError“,:message =>”预期为#,

mongodb - 如何在mongodb中查询嵌套的json对象?