Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 655
Rahul Avatar asked Jan 04 '13 09:01

Rahul


1 Answers

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?

like image 159
dadoonet Avatar answered Sep 27 '22 17:09

dadoonet