Hi,
good question, as you said you can't retrieve the fields with the document Get API or by searching. But refering to the blog post you mentioned, the fields that are later used in aggregations are declared as having "doc_values": true
in the mappings. This means that for those fields the data is stored on disk using the doc_values data structure which is optimized for use in aggregations but cannot be searched.
You can still take a look at those values using fielddata_fields functionality. Here is a small example:
PUT /test
{
"mappings": {
"type": {
"_all": { "enabled": false },
"_source": { "enabled": false },
"properties": {
"count": {
"type": "integer", "doc_values": true, "index": "no" }
}
}
}
}
PUT /test/type/1
{
"count" : 5,
"age": 21
}
PUT /test/type/2
{
"count" : 10,
"age" : 13
}
GET /test/type/1
GET /test/type/_search
{
"query": {
"ids": {
"values" : ["1"]
}
},
"fielddata_fields": ["count"]
}
With the above mapping, searching for "count" e.g. with a range query will give you a exception because the field is not indexed. However, using the "ids" query to filter one (or more) documents, you can see the field data (or in this case doc_values) of that field.