Hello everyone
I want to get the aggregation result with filter the bucket key value. And My query is
> {
> "query": {
> "bool": {
> "filter": [
> {
> "term": {
> "customer_id": "123456"
> }
> },
> {
> "range": {
> "date": {
> "gte": "2019-04-20",
> "lte": "2020-04-14"
> }
> }
> }
> ]
> }
> },
> "size": 0,
> "aggs": {
> "search_terms": {
> "composite": {
> "size": 10,
> "sources": {
> "search_term": {
> "terms": {
> "field": "search_term_standard"
> }
> }
> }
> },
> "aggs": {
> "clicks": {
> "sum": {
> "field": "clicks",
> "missing": 0
> }
> },
> "conversions_rate": {
> "avg": {
> "field": "conversions_rate",
> "missing": 0
> }
> },
> "cost": {
> "sum": {
> "field": "cost",
> "missing": 0
> }
> },
> "conversions": {
> "sum": {
> "field": "conversions",
> "missing": 0
> }
> },
> "avg_cpc": {
> "avg": {
> "field": "avg_cpc",
> "missing": 0
> }
> },
> "conversions_value": {
> "sum": {
> "field": "conversions_value",
> "missing": 0
> }
> }
> }
> }
> }
> }
The mapping is
"mappings": {
- "_doc": {
- "properties": {
- "ctr": {
- "type": "float"},
- "date": {
- "type": "date"},
- "conversions": {
- "type": "integer"},
- "cost": {
- "type": "integer"},
- "conversions_value_cost": {
- "type": "float"},
- "search_term_bigram": {
- "fielddata": true,
- "analyzer": "bigram",
- "type": "text"},
- "campaign_name": {
- "type": "text",
- "fields": {
- "keyword": {
- "ignore_above": 256,
- "type": "keyword"}}},
- "conversions_value": {
- "type": "float"},
- "@timestamp": {
- "type": "date"},
- "cost_conversions": {
- "type": "float"},
- "value_conversions": {
- "type": "float"},
- "search_term_id": {
- "type": "long"},
- "updated_at": {
- "type": "date"},
- "conversions_rate": {
- "type": "float"},
- "search_term_trigram": {
- "fielddata": true,
- "analyzer": "trigram",
- "type": "text"},
- "search_term": {
- "type": "text",
- "fields": {
- "keyword": {
- "ignore_above": 256,
- "type": "keyword"}}},
- "avg_cpc": {
- "type": "integer"},
- "clicks": {
- "type": "integer"},
- "impression": {
- "type": "integer"},
- "id": {
- "type": "long"},
- "customer_id": {
- "type": "text",
- "fields": {
- "keyword": {
- "ignore_above": 256,
- "type": "keyword"}}},
- "search_term_standard": {
- "fielddata": true,
- "analyzer": "standard",
- "type": "text"},
- "campaign_id": {
- "type": "text",
- "fields": {
- "keyword": {
- "ignore_above": 256,
- "type": "keyword"}}}}}
and the result is
{
- "took": 1161,
- "timed_out": false,
- "_shards": {
- "total": 1,
- "successful": 1,
- "skipped": 0,
- "failed": 0},
- "hits": {
- "total": {
- "value": 10000,
- "relation": "gte"},
- "max_score": null,
- "hits": },
- "aggregations": {
- "search_terms": {
- "after_key": {
- "search_term": "0.0"},
- "buckets": [
- {
- "key": {
- "search_term": "0"},
- "doc_count": 392,
- "conversions_value": {
- "value": 114.4799977555},
- "conversions": {
- "value": 367},
- "cost": {
- "value": 7640},
- "conversions_rate": {
- "value": 0.8928571428571429},
- "avg_cpc": {
- "value": 188.0612244898},
- "clicks": {
- "value": 342}}
, * {- "key": {
- "search_term": "0.0"},
- "doc_count": 1,
- "conversions_value": {
- "value": 0},
- "conversions": {
- "value": 0},
- "cost": {
- "value": 800},
- "conversions_rate": {
- "value": 0},
- "avg_cpc": {
- "value": 800},
- "clicks": {
- "value": 1}}]}}
}
I want to filter the aggregations buckets only show the search_term contains "for".
How can I do it ? Thank you.