0
votes

I am trying to create one index with multiple types for each data source.

The following mapping does create mapping for one type:

curl -XPUT localhost:9200/test -d '{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false },
            "properties" : {
                "field1" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    },
    "mappings" : {
        "type2" : {
            "_source" : { "enabled" : false },
            "properties" : {
                "source1" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    }
}'

When I run this:

curl -X GET 'http://localhost:9200/test/tpe1/_mapping?pretty=true'

Nothing is displayed.

How can I create mapping for multiple types in elastic search?

2

2 Answers

0
votes

While there is probably a way to do this in a single call, it's just as easy to do it in multiple calls which keeps things more separate.

PUT hilden1

PUT hilden1/type1/_mapping
{
  "properties": {
    "value1": {
      "type": "string"
    }
  }
}

PUT hilden1/type2/_mapping
{
  "properties": {
    "value2": {
      "type": "string"
    }
  }
}


GET hilden1/_mapping

Setting the mapping on 2 calls also has the added benefit of not affecting a 3rd type within the same index.

0
votes

First of All, You will applied mapping to Elastic search

curl -XPUT localhost:9200/index/_setting -d @indexsetting.json

Create a Two json file for Type1 and Type2 Mapping Mapping1.json:

{
"type1":{
"properties" : {
 "field1" : { "type" : "string", "index" : "not_analyzed" } 
}}} 

Mapping2.json

{
"type2":{
"properties" : {
 "field1" : { "type" : "string", "index" : "not_analyzed" } 
}}} 

then,you will execute below query one by one

curl -XPUT localhost:9200/index/type1/_mapping -d @mapping1.json
curl -XPUT localhost:9200/index/type2/_mapping -d @mapping2.json

This is properly correct way for Create a index and Mappping in Elastic search.