Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

mapping in create index in elasticsearch through mongodb river is not taking effect

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 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.

What am I doing wrong ??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Then you can define a mapping for your type:

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

Does it help?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...