Wednesday, 12 April 2017

Elastic search mapping using node.js

i have created a elastic search index using below DSL query - it is already created manually but i am trying to index data using mongosastic with node.js. I am using synchronize method to index my mongodb collection to elastic search. what should be my nodejs mapping code so that it can be indexed properly ?

        { 
           "settings": { 
              "number_of_shards": 1, 
              "analysis": { 
                 "filter": { 
                    "ngram_filter": {    // ngrams analyzers
                       "type": "ngram", 
                       "min_gram": 2, 
                       "max_gram": 20 
                    } 
                 }, 
                 "analyzer": { 
                    "ngram_analyzer": { 
                       "type": "custom", 
                       "tokenizer": "standard", 
                       "filter": [ 
                          "lowercase", 
                          "ngram_filter" 
                       ] 
                    } 
                 } 
              } 
           }, 
           "mappings": { 
              "employees": { 
                 "_all": { 
                    "type": "string", 
                    "index_analyzer": "ngram_analyzer", 
                    "search_analyzer": "standard" 
                 }, 
                 "properties": {    // schema start
                    "FirstName": { 
                       "type": "string", 
                       "include_in_all": true, 
                       "term_vector": "yes", 
                       "index_analyzer": "ngram_analyzer", 
                       "search_analyzer": "standard" 
                    }  // it has more fiels as given in schema below
                 }      // schema end
              } 
           } 
        }

        my mongodb collection schema is - 
        {
        "FirstName": "MISTI",
        "LastName": "RAMSTAD",
        "Designation": "CEO",
        "Salary": "148000",
        "DateOfJoining": "23/09/1997",
        "Address": "32 Pawnee Ave. San Pablo, CA 94806",
        "Gender": "Female",
        "Age": 55,
        "MaritalStatus": "Unmarried",
        "I`enter code here`nterests": "Letterboxing,Scuba Diving,Mountain Biking,Handwriting Analysis,Models"
    }



via karambir

No comments:

Post a Comment