I have index with dynamic mapping
'mappings' => [
'index_type' => [
'dynamic_templates' => [
[
'property_name' => [
'match_mapping_type' => '*',
'match' => 'name_property_*',
'mapping' => [
'type' => 'text',
'index' => TRUE,
],
],
],
],
],
],
Now i queried like this
[
'size' => 1,
'from' => 0,
'_source' => [],
'query' => [
'multi_match' => [
'query' => 'query',
'type' => 'best_fields',
'fields' => ['name_property_*'],
],
],
and query successfully executed like this
['_index'] => 'index_name'
['_type'] => 'index_type'
['_id'] => 1325
['_score'] => 0.28
['_source'] => Array
(
['name_property_1'] => 'country',
['name_property_2'] => 'query',
['name_property_3'] => 'state'
)
Now my question is how to return only fields that match the actual query in this example how to achieve output like this
['_index'] => 'index_name'
['_type'] => 'index_type'
['_id'] => 1325
['_score'] => 0.28
['_source'] => Array
(
['name_property_2'] => 'query',
)
only name_property_2 because this field only match with the query i do not want to return whole document.