I have a problem with using elastic search at the moment. When I try to perform a search and only want a subset of the fields returned, I need to specify the fields using a dot-notation if the fields are nested. Here’s a sample of my mapper json document which maps my couchDB document:
{
"product": {
"_type": {"store": "yes"},
"_source": {"compress": true},
"index_analyzer": "standard",
"search_analyzer": "standard",
"dynamic_date_formats": ["date_time_no_millis", "date_optional_time"],
"properties": {
"_id": {"type": "string", "store": "yes", "index": "not_analyzed"},
"key": {"type": "string", "store": "yes"},
"content": {
"type": "object",
"path": "just_name",
"properties": {
"key": {"type": "string", "store": "yes"},
"name": {"type": "string", "store": "yes", "index_name": "name"},
"description": {"type": "string", "store": "yes", "index_name": "description"},
"brand": {
"type": "object",
"index_name": "brand",
"properties": {
"abbreviation": {"type": "string", "store": "yes", "index_name": "brand_abbreviation"},
"name": {"type": "string", "store": "yes", "index_name": "brand_name"}
}
}
}
}
}
}
}
Referring to _id would just be a simple _id, but say I wanted to refer to name in the content, I would have to refer to it as content.name. The problem with this is that when the search output is out, the json output contains the field name as: “content.name”.
Is it possible to rename this as “name” and without the “content.” prefix? You can see, I tried to specify index_name, but that seemed useless.
You can use
partial_fieldsto do this.For instance, if you index a doc like this:
You can include the fields/objects that you want like this:
Which will give you a result like this: (note the missing
emailfield, and that fieldfooremains a hash – it is not flattened with dot notation)On a side note, some comments about your mapping:
_idfield (which I assume is meant to be the elasticsearch ID, not an external ID) is at the wrong level – it should be at the same level as_type. If it IS an external ID, then it’s at the right level._sourcefield, it is much faster to retrieve just that field and parse it, rather than hitting the disk for each individual field.