I have a JSON data that maps automatically by the elastic search when I'm indexing the data. How can I exclude some fields in the mapping. I already tried to define the map manually but when I'm doing bulk index, It automatically maps the other fields.
ex. my JSON data looks like this
[
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
},
...
My map when I'm defining it manually
PUT myindex
{
"mappings": {
"product": {
"properties": {
"id": { "type": "text },
"name": { "type": "text"},
"description": { "type": "text" },
"is_active": { "type": "boolean" }
}
}
}
}
What I want to achieve is the data still remain I just want to exclude the image property to be not included in the indexing.
So that When I query in the elastic search is still I get the data with image
Is that possible?
Thank you guys. I'm new in elasticsearch
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
}
There are two recommended methods to retrieve selected fields from a search query: Use the fields option to extract the values of fields present in the index mapping. Use the _source option if you need to access the original data that was passed at index time.
You cannot delete the status field from this mapping. If you really need to get rid of this field, you'll have to create another mapping without status field and reindex your data.
By default, Elasticsearch indexes all data in every field and each indexed field has a dedicated, optimized data structure. For example, text fields are stored in inverted indices, and numeric and geo fields are stored in BKD trees.
An inverted index consists of all of the unique terms that appear in any document covered by the index. For each term, the list of documents in which the term appears, is stored. So essentially an inverted index is a mapping between terms and which documents contain those terms.
Yes, that's possible simply by adding dynamic: false
to your mapping, like this:
PUT myindex
{
"mappings": {
"product": {
"dynamic": false, <-- add this line
"properties": {
"id": {
"type": "text"
},
"name": {
"type": "text"
},
"description": {
"type": "text"
},
"is_active": {
"type": "boolean"
}
}
}
}
}
The image
array will still be in the source, but the mapping won't be modified.
The problem with the accepted answer is, that you need to explicitly add mappings for all fields, which is not always wanted (e.g. for array types). You could disable the field like this:
PUT myindex
{
"mappings": {
"product": {
"properties": {
"id": { "type": "text },
"name": { "type": "text"},
"description": { "type": "text" },
"is_active": { "type": "boolean" },
"image": { "type": "object, "enabled": false }
}
}
}
}
The image
array is still going to be in the _source.
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With