Generating an aggregate field during search query

Hi all, new to ES here. I'm trying to implement a search engine from a source with the following schema in 1 index:

index:paper
{
"title": string,
"author": string,
"id": string,
"references": [another_paper.id, another_paper.id, ...],
"pubDate": date
}

Let's say I want to perform a search for papers with the author "A. Smith" between the dates 2017-01-09 to 2017-01-30, and the number of times that each paper are referenced. How would I craft my search query to get results with a generated a field that says how many times each returned document is referenced by other documents under the "references" field? Is this even possible in ES? Execution speed is not important and I can tolerate relatively slow execution speed, but I do not want to update existing documents when I upload new documents.

Thank you

Hey,

I think you want to aggregate on the references, but you want to use a cardinality aggregation in there to get the number of distinct references. See https://www.elastic.co/guide/en/elasticsearch/reference/6.1/search-aggregations-metrics-cardinality-aggregation.html

--Alex

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.