Is there an option in elastic search to store vales just for the purpose of retrieving and not used for searching? So when indexing we'll index all fields and when searching we'll search on a single field only, but need other data as well. For example, we'll index products, fields could be Name, SKU, Supplier Name etc. Out of which, only Name needs to be indexed and searched. SKU and Supplier Name are just for storing and retrieving with a search.
CodePudding user response:
Use the enabled: false
option at field definition to make a field non-indexed.
CodePudding user response:
Since the _source
document is stored anyway, the best way to achieve what you want is to neither store nor index any fields, except the one you're searching on, like this:
PUT my-index
{
"mappings": {
"_source": {
"enabled": true <--- true by default, but adding for completeness
},
"properties": {
"name": {
"type": "text",
"index": true <--- true by default, but adding for completeness
},
"sku": {
"type": "keyword",
"index": false, <--- don't index this field
"store": false <--- false by default, but adding for completeness
},
"supplier": {
"type": "keyword",
"index": false, <--- don't index this field
"store": false <--- false by default, but adding for completeness
},
}
}
}
So to sum up:
- the fields you want to search on must have
index: true
- the fields you don't want to search on must have
index: false
store
is false by default so you don't need to specify it_source
is enabled by default, so you don't need to specify itenabled
should only be used at the top-level or onobject
fields, so it doesn't have its place here
With the above mapping, you can
- search on
name
- retrieve all fields from the
_source
document since the_source
field is stored by default and contains the original document