0
votes

I'm using the example application from github.com/searchly/searchly-php-sample with Searchly service.

I've came a simple where I want the search results to return all the aggregations(continued as 'aggs') from the search results, not only the ones I specified.

Currently the code for the aggs is:

$searchParams['body']['aggs']['resolution']['terms']['field'] = 'resolution';

this returns the resolution agg but I can not find the way for it to return all of the possible aggs from the search results.

Is it possible or does it require me to save the aggs some where and then just list them when I do the actual search request?

Thank you!

1
I don't understand this question at all. Can you try to explain what you mean by return 'all' the aggregations?Perryn Fowler
From the original document I have "$searchParams['body']['aggs']['ram']['terms']['field'] = 'ram'; $searchParams['body']['aggs']['hard_drive']['terms']['field'] = 'hard_drive'; $searchParams['body']['aggs']['core']['terms']['field'] = 'core'; " This returns these 3 filters on the left of the page and I can filter them. Can I return all the filters without specifying them this way?TrueSkillZ
So you want to perform a terms aggregation on all fields?Perryn Fowler
Yes. But I can't seem to find a way for it to return all the fields(lets say from the example 'ram','hard_drive','core' without actually writing the 3 lines. I created the 4th one names 'cpu' which holds INTEL or AMD. how can I get all 4 of them without writting $searchParams['body']['aggs']['cpu']['terms']['field'] = 'cpu'; and so on. Thank for the help!TrueSkillZ
Whats the problem with specifying each field? Don't you know what they all are or something?Perryn Fowler

1 Answers

0
votes

As far as I know there is no way to do this directly - you have to specify each field you are interested in.

However if you can build up a list of all the fields in the index then you could generate the required aggregations fairly easily.

So, how to build up that list? I can think of three ways that might work

A) build it up by doing some pre-processing before you index each document into ElasticSearch

B) Use the GET MAPPING api to see what fields have been created by dynamic mapping (http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)

C) Use a Scripted Metric Aggregation and write scripts that build up a de-duped list of fields in the documents (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)