I have an elasticsearch index that has this fields: user_id, agent_name, city, ...
I want to run a query for selecting records where agent_name "agent1" is one of the agents but there are also other agents, and then select those that their agents are in more than 2 cities.
I used this query:
query = {
"size": 0, # Don't need the actual documents, just the aggregation results
"query": {
{"match": {agent_name: 'agent1'}
},
"aggs": {
"user_ids": {
"terms": {"field": "user_id", "size": 60000},
"aggs": {
"city_count": {"cardinality": {"field": "city"}}
}
}
},
}
in above example if i run the query it first of all, selects records that just all of agent_name values is 'agent1', then aggregates the result, this way i get the result if agent1 is active in 2 cities, but i want it to select a record if one of it's agent is 'agent1' and also have other agents other than agent1, how should I change 'query' part to get desired result?