Skip to content
Advertisement

Distinct value in elastic search with extra field inside {“key”: “xyz”, “doc_count”: 1}

I am working on Elastic Search (version 7.16) with Oython (version 3.6)

I have the below rows in Elastic Search:

JavaScript

With the below query:

JavaScript

I get distinct table values, something like below:

JavaScript

But what I actually want is:

JavaScript

I want to know from which database is this table coming from, not just {'key': 'sales_tab', 'doc_count': 2} like extra key: value of database {'key': 'sales_tab', 'doc_count': 2, "database": "postgres"} value in buckets result or any other solution which will give distinct table along with the database it is coming from.

How do I achieve it?

Advertisement

Answer

You can use sub aggregation for getting database name as shown below:

JavaScript

This will generate response as shown below:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement