I have an elasticsearch document named "user", which contains an array
field - "companies". I want to get all the company names that contains
"xyz" in their name. I have set the custom mapping which tokenizes the data
in the companies array.
Below is the mapping defined for companies array:
field :companies, type: 'string', index: 'analyzed', analyzer:
'name_analyzer' do
field :companies_lower, type: 'string', index: 'analyzed', analyzer:
'lower_keyword'
field :companies_untouched, type: 'string', index: 'not_analyzed'
end
(name_analyzer is the custom analyzer defined by me)
I have these two ES documents:
{"companies":["xyzz","abc"]}
{"companies":["abcd","abcde"]}
Now, when I perform this query:
{"query"=>{"match_all"=>{}},
"facets"=>
{"tags"=>
{"terms"=>{"field"=>"companies_untouched"},
"facet_filter"=>{"term"=>{"companies"=>"xyz"}}}}}
This is the result that I get:
{"tags"=>
{"_type"=>"terms",
"missing"=>0,
"total"=>3,
"other"=>0,
"terms"=>
[{"term"=>"xyzz", "count"=>1},
{"term"=>"abc", "count"=>1}]}}
But I need only the matching result like below:
{"tags"=>
{"_type"=>"terms",
"missing"=>0,
"total"=>3,
"other"=>0,
"terms"=>
[{"term"=>"xyzz", "count"=>1}]}}
i.e the results should only contain the array values that are matching my
search query. Is there something wrong that I am doing here?
Thanks,
Aash
--