PUT /people
{
"mappings": {
"dynamic": false,
"properties": {
"first_name": {
"type": "text"
}
}
}
}
PUT /people
{
"mappings": {
"dynamic": "strict",
"properties": {
"first_name": {
"type": "text"
}
}
}
}
POST /people/_doc
{
"first_name": "Bo",
"last_name": "Andersen"
}
GET /people/_mapping
GET /people/_search
{
"query": {
"match": {
"first_name": "Bo"
}
}
}
GET /people/_search
{
"query": {
"match": {
"last_name": "Andersen"
}
}
}
The following example sets the dynamic
parameter to "strict"
at the root level, but overrides it with a value of
true
for the specifications.other
field mapping.
PUT /computers
{
"mappings": {
"dynamic": "strict",
"properties": {
"name": {
"type": "text"
},
"specifications": {
"properties": {
"cpu": {
"properties": {
"name": {
"type": "text"
}
}
},
"other": {
"dynamic": true,
"properties": { ... }
}
}
}
}
}
}
POST /computers/_doc
{
"name": "Gamer PC",
"specifications": {
"cpu": {
"name": "Intel Core i7-9700K",
"frequency": 3.6
}
}
}
POST /computers/_doc
{
"name": "Gamer PC",
"specifications": {
"cpu": {
"name": "Intel Core i7-9700K"
},
"other": {
"security": "Kensington"
}
}
}
When enabling numeric detection, Elasticsearch will check the contents of strings to see if they contain only numeric
values - and map the fields accordingly as either float
or long
.
PUT /computers
{
"mappings": {
"numeric_detection": true
}
}
POST /computers/_doc
{
"specifications": {
"other": {
"max_ram_gb": "32", # long
"bluetooth": "5.2" # float
}
}
}
PUT /computers
{
"mappings": {
"date_detection": false
}
}
PUT /computers
{
"mappings": {
"dynamic_date_formats": ["dd-MM-yyyy"]
}
}
DELETE /people