Skip to content

Instantly share code, notes, and snippets.

@szabizs
Last active January 23, 2023 22:13
Show Gist options
  • Save szabizs/efa7e80a5ebf5553792848e1741d8163 to your computer and use it in GitHub Desktop.
Save szabizs/efa7e80a5ebf5553792848e1741d8163 to your computer and use it in GitHub Desktop.
Create an Elasticsearch index with mapping for an ecommerce project
curl --location --request PUT 'localhost:9200/ecom' \
--header 'Content-Type: application/json' \
--data-raw '{
"mappings": {
"dynamic": true,
"properties": {
"title": {
"type": "text",
"copy_to": "all_filters"
},
"description": {
"type": "text",
"copy_to": "all_filters"
},
"sku": {
"type": "keyword",
"copy_to": "all_filters"
},
"price": {
"type": "float"
},
"category": {
"type": "keyword",
"copy_to": "all_filters"
},
"is_active": {
"type": "boolean",
"null_value": false
},
"is_featured": {
"type": "boolean",
"null_value": false
},
"available_quantity": {
"type": "integer"
},
"labels": {
"type": "nested",
"properties": {
"label": {
"type": "keyword",
"copy_to": "all_filters"
},
"color": {
"type": "keyword"
}
}
},
"images": {
"type": "nested",
"properties": {
"is_main": {
"type": "boolean",
"null_value": false
},
"thumbnail": {
"type": "text"
},
"medium": {
"type": "text"
},
"original": {
"type": "text"
}
}
},
"filters": {
"type": "nested",
"properties": {
"name": {
"type": "keyword",
"copy_to": "all_filters"
},
"value": {
"type": "keyword",
"copy_to": "all_filters"
},
"label": {
"type": "keyword",
"copy_to": "all_filters"
},
"pretty_name": {
"type": "keyword",
"copy_to": "all_filters"
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment