Assaf Lavie
Assaf Lavie

Reputation: 75983

Is it possible to define default mapping for an inner object in ElasticSearch?

Say I have a document like this:

{
    "events" : [
        { 
         "event_id" : 123,
         "props" : {
              "version": "33"
        },
        {
         "event_id" : 124,
         "props" : {
              "version": "44a"
         }
    ]
}

Is it possible to specify that the events.props.version be mapped to some type?

I've tried:

{
  "template" : "logstash-*",
  ...
  "mappings" : {
    "_default_" : {
       "properties" : {
         "events.props.version" : { "type" : "string" }
       }
    }
  }
}

But that doesn't seem to work.

Upvotes: 0

Views: 110

Answers (2)

Arun Prakash
Arun Prakash

Reputation: 1727

Please have a look at mapping API in elasticsearch Mapping API.

To set any analyzer in the inner element we need to consider each and every inner field as a separate properties set. try the following

{
    "mappings": {
        "properties": {
            "events": {
                "properties": {
                    "event_id": {
                        "type": "string",
                        "analyzer": "keyword"
                    },
                    "props": {
                        "properties": {
                            "version": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

if this not works please provide me you mapping.

Upvotes: 1

user1750065
user1750065

Reputation: 31

Sure, but you need to use the "object" type:

From the doc ( https://www.elastic.co/guide/en/elasticsearch/reference/1.5/mapping-object-type.html ) if you want to map

{
    "tweet" : {
        "person" : {
            "name" : {
                "first_name" : "Shay",
                "last_name" : "Banon"
            },
            "sid" : "12345"
        },
        "message" : "This is a tweet!"
    }
}

you can write:

{
    "tweet" : {
        "properties" : {
            "person" : {
                "type" : "object",
                "properties" : {
                    "name" : {
                        "type" : "object",
                        "properties" : {
                            "first_name" : {"type" : "string"},
                            "last_name" : {"type" : "string"}
                        }
                    },
                    "sid" : {"type" : "string", "index" : "not_analyzed"}
                }
            },
            "message" : {"type" : "string"}
        }
    }
}

Upvotes: 1

Related Questions