# Identify the KEY to which pattern got a match

**URL:** <https://discuss.elastic.co/t/identify-the-key-to-which-pattern-got-a-match/130810>\
**Category:** Elasticsearch\
**Created:** [May 7, 2018, 10:17am UTC](https://discuss.elastic.co/t/identify-the-key-to-which-pattern-got-a-match/130810 "2018-05-07T10:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NormalGuy](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@NormalGuy](https://discuss.elastic.co/u/NormalGuy)\
**Post date:** [May 7, 2018, 10:17am UTC](https://discuss.elastic.co/t/identify-the-key-to-which-pattern-got-a-match/130810/1 "2018-05-07T10:17:48Z")

</div>

```
How do I make a similar query using QueryBuilders in Java? I am looking for a way to identify which key , the pattern got a matched. 

{
  "should": [
    {
      "match": {
        "description": {
          "query": "pattern",
          "_name": "description"
        }
      }
    },
    {
      "match": {
        "author": {
          "query": "pattern",
          "_name": "author"
        }
      }
    },
    {
      "match": {
        "headline": {
          "query": "pattern",
          "_name": "headline"
        }
      }
    }
  ]
}

```

As of now I am doing this in my Java code. I don't know how to add an identifier for the key ("like \_name" in the above json") 🙂

```
	QueryBuilder query = QueryBuilders.boolQuery()
							.should(QueryBuilders.matchQuery("description", sPattern))
                                                        .should(QueryBuilders.matchQuery("author", sPattern))
							.should(QueryBuilders.matchQuery("headline", sPattern));
```

---

<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:** [June 4, 2018, 10:17am UTC](https://discuss.elastic.co/t/identify-the-key-to-which-pattern-got-a-match/130810/2 "2018-06-04T10:17:48Z")

</div>

Closed on June 4, 2018, 10:17am UTC

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