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


Solution 1:[1]

you can see the below answer, you can create the index with settings and mapping from your index.ts file when the server start.

also if you want to update your mapping just make your update and restart the server.

Elastic Search when to add dynamic mappings

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rafiq