简体   繁体   中英

elasticsearch returning all found aggregations

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!

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM