Karthikeyan
Karthikeyan

Reputation: 2001

Not able to create elasticsearch's mappings for the index created from logstash JDBC input plugin

Am trying to create mappings for elasticsearch index. When i create an index with the below query, am able to apply mappings.

Please find the query that am create index in elasticsearch

put index/profile/1
{
    "firstname" : "Karthik",
    "lastname" : "AS",
    "address" : "4/167, SouthExtn, shanmuga nagar, NA",
    "Skill" : "Java, JEE, ReactJS, ActiveMQ, ElasticSearch",
    "filename" : "My_second_file_created_at_2012.01.13.pdf"
}

for the above created index am able to apply mappings and able to search successfully. Please find the below mappings details

    PUT /documents_test8
{
   "settings" : {
      "analysis" : {
         "analyzer" : {
            "filename_search" : {
               "tokenizer" : "filename",
               "filter" : ["lowercase"]
            },
            "filename_index" : {
               "tokenizer" : "filename",
               "filter" : ["lowercase","edge_ngram"]
            }
         },
         "tokenizer" : {
            "filename" : {
               "pattern" : "[^\\p{L}\\d]+",
               "type" : "pattern"
            }
         },
         "filter" : {
            "edge_ngram" : {
               "side" : "front",
               "max_gram" : 20,
               "min_gram" : 1,
               "type" : "edgeNGram"
            }
         }
      }
   },
   "mappings" : {
      "doc" : {
         "properties" : {
            "filename" : {
               "type" : "text",
               "search_analyzer" : "filename_search",
               "index_analyzer" : "filename_index"
            }
         }
      }
   }
}

But in actual scenario, am creating index in elasticsearch via logstash JDBC input plugin. Am able to create index in elasticsearch, but the problem once index is created in elasticsearch via logstash by default mappings also created for that index (for all the fields). After that am not able to apply my mappings it shows index [documents_test9/P07B6_6mRqmH9IP-UaCjrw] already exists error. If i try to delete that index and executing this mapping am getting Failed to parse mapping [doc]: No handler for type [string] declared on field [filename] error.

Not sure, how to apply mappings when the index is created via logstash JDBC input plugin

Upvotes: 0

Views: 400

Answers (1)

Polynomial Proton
Polynomial Proton

Reputation: 5135

If I understand the question correctly, you can use a index template with a wildcard so any new index that contain a name matching in the wildcard will use the given index template by default.

With below template, any index you add which contains the name documents* i.e. documents1, documents_test8 etc, will by default use the given index template.

 PUT _template/documents
{
  "template": "documents*",
   "settings" : {
      "analysis" : {
         "analyzer" : {
            "filename_search" : {
               "tokenizer" : "filename",
               "filter" : ["lowercase"]
            },
            "filename_index" : {
               "tokenizer" : "filename",
               "filter" : ["lowercase","edge_ngram"]
            }
         },
         "tokenizer" : {
            "filename" : {
               "pattern" : "[^\\p{L}\\d]+",
               "type" : "pattern"
            }
         },
         "filter" : {
            "edge_ngram" : {
               "side" : "front",
               "max_gram" : 20,
               "min_gram" : 1,
               "type" : "edgeNGram"
            }
         }
      }
   },
   "mappings" : {
      "doc" : {
         "properties" : {
            "filename" : {
               "type" : "text",
               "search_analyzer" : "filename_search",
               "index_analyzer" : "filename_index"
            }
         }
      }
   }
}

Upvotes: 1

Related Questions