# Query Elasticsearch to get count of Keywords within matched Keywords

**URL:** https://discuss.elastic.co/t/query-elasticsearch-to-get-count-of-keywords-within-matched-keywords/217945
**Category:** Elasticsearch
**Created:** [February 5, 2020, 9:48am UTC](https://discuss.elastic.co/t/query-elasticsearch-to-get-count-of-keywords-within-matched-keywords/217945 "2020-02-05T09:48:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rakmo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rakmo/32/55441_2.png) [@rakmo](https://discuss.elastic.co/u/rakmo)
#### Post date: [February 5, 2020, 9:48am UTC](https://discuss.elastic.co/t/query-elasticsearch-to-get-count-of-keywords-within-matched-keywords/217945/1 "2020-02-05T09:48:08Z")

</div>

**Data** :

```
Doc 1:
       field_a : ["A", "B", 'C", "D", "E"]

Doc 2:
       field_a : ["A", "D", "G", "Z", "Y"]

Doc 3:
       field_a : ["F", "W", 'C"]

Doc 4:
       field_a : ["A", "B", 'C", "D", "E", "Z", "Y"]

Doc 5:
       field_a : ["A", "B", "C"]

```

PS: `field_a` is of _Keyword_ type.

**Query** :

`terms: ["A", "B", "C", "D", "E"]`

**Required Response** :

```
Doc 1: 5
Doc 2: 2
Doc 3: 1
Doc 4: 5
Doc 5: 3

```

Require the required response. It will be perfect if there is any way to generate **Custom Score Function** to get the same.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 4, 2020, 9:48am UTC](https://discuss.elastic.co/t/query-elasticsearch-to-get-count-of-keywords-within-matched-keywords/217945/2 "2020-03-04T09:48:09Z")

</div>

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