0

I'm putting data in ES and check the mapping which is created,

I'm executing this:

curl -XPOST 'http://localhost:9200/testnested2/type1/0' -d '{
  "p1": ["1","2","3","4"], 
   "users" : {
      "first" : "John",
      "last" :  "Sm11ith" 
   }
}'

and this is the schema it created:

{
  "testnested2":{
     "mappings":{
       "type1":{
          "properties":{
            "p1":{"type":"string"},
            "users":{
              "properties":{
                 "first":{"type":"string"},
                 "last":{"type":"string"}
               }
            }
         }
       }
     }
   }
}

I was wondering if it's possible to tell it that "users" is nested or I have to create the mapping for myself.

I would like that ES could create an shema like this:

   curl -XPOST http://180.5.5.93:9200/testnested3 -d '{
        "settings" : {
            "number_of_shards" : 1
        },
        "mappings" : {  
        "type1" : {
            "properties" : {
                "propiedad1" : { "type" : "string"},
                "users" : {
                    "type" : "nested",
                    "include_in_parent": true,
                    "properties": {
                        "first" : {"type": "string" },
                        "last"  : {"type": "string" }
                    }
                }
            }
        }
        }
    }'
2
  • "first" and "last" are nested under "users" - is this what you want? if not can you post an example of what you want? Commented Dec 31, 2014 at 9:56
  • I editeded, really, I could do it for myself, it's not too much, I'm just curious about the possible to automatize this part. Commented Dec 31, 2014 at 10:27

1 Answer 1

1

By default, the dynamic mapping feature of ElasticSearch will map users as an object instead of nested.

If you want to tune this behavior, you have to define explicitely a users attribute as nested either in :

  • the type1 mapping
  • the default mapping of your index. This way, for any type created, the users attribute will be set automatically to nested(see here for default mapping information)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.