Example uses basic HTTP, which translate easily to cURL and other HTTP applications. They also match the Sense syntax, which will be renamed to Console in Kibana 5.0.
Note: The example inserts <#> to help draw attention to parts. Those should be removed if you copy it!
DELETE /my_index <1>
PUT /my_index/my_type/abc123 <2>
{
"field1" : 1234, <3>
"field2" : 456,
"object1" : {
"field1" : 7.8 <4>
}
}
my_index, with the type, my_type, and the ID abc123 (could be numeric, but it is always a string).
long rather than an integer or a short (both of which could contain 1234 and 456).double instead of a float as you might want.This dynamically created index and type roughly match the mapping defined in the first example. However, it's critical to understand how <3> and <4> impact the automatically defined mappings.
You could follow this by adding yet another type dynamically to the same index:
PUT /my_index/my_other_type/abc123 <1>
{
"field1": 91, <2>
"field3": 4.567
}
abc123 other than that it happens to be in the same index.field1 already exists in the index, so it must be the same type of field as defined in the other types. Submitting a value that was a string or not an integer would fail (e.g., "field1": "this is some text" or "field1": 123.0).This would dynamically create the mappings for my_other_type within the same index, my_index.
Note: It is always faster to define mappings upfront rather than having Elasticsearch dynamically perform it at index time.
The end result of indexing both documents would be similar to the first example, but the field types would be different and therefore slightly wasteful:
GET /my_index/_mappings <1>
{
"mappings": {
"my_type": { <2>
"properties": {
"field1": {
"type": "long"
},
"field2": {
"type": "long" <3>
},
"object1": {
"type": "object",
"properties": {
"field1" : {
"type": "double" <4>
}
}
}
}
}
},
"my_other_type": { <5>
"properties": {
"field1": {
"type": "long"
},
"field3": {
"type": "double"
}
}
}
}
_mappings endpoint to get the mappings from the index that we created.my_type in the first step of this example.field2 is now a long instead of an integer because we did not define it upfront. This may prove to be wasteful in disk storage.object1.field1 is now a double for the same reason as #3 with the same ramifications as #3.
long can be compressed in a lot of cases. However, a double cannot be compressed due to it being a floating point number.my_other_type in the second step of this example. Its mapping happens to be the same because we were already using long and double.
field1 must match the definition from my_type (and it does).field3 is unique to this type, so it has no such restriction.