# Term matching without using keyword in the field name

**URL:** <https://discuss.elastic.co/t/term-matching-without-using-keyword-in-the-field-name/182562>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 5:39am UTC](https://discuss.elastic.co/t/term-matching-without-using-keyword-in-the-field-name/182562 "2019-05-24T05:39:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashank\_reddy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shashank_reddy/32/46758_2.png) [@Shashank\_reddy](https://discuss.elastic.co/u/Shashank_reddy)\
**Post date:** [May 24, 2019, 5:39am UTC](https://discuss.elastic.co/t/term-matching-without-using-keyword-in-the-field-name/182562/1 "2019-05-24T05:39:05Z")

</div>

I am trying to use Elastic Search for both free text search and structured search. In order filter documents during structured search, exact matches are desired and I understand that term matches can achieve this. However, is there any abstraction that can prevent me from knowing the underlying type of data/ field name I am querying. I would like to filter a bunch of fields: foo, bar, baz with a certain value each. However, I do not know the underlying type of each of them at query time but I want to do an exact match. In the below example, foo and bar are text fields and baz is a long field. So, I need a way for my query engine to understand that foo and bar are text fields and baz is a long field to be able to skip the `keyword` tag in the term clause. Is there a way to abstract/ generalize this with additional options in a match clause or term clause?

```auto
{
 "query": {
   "bool": {
     "filter": [
       {
         "term": {
           "foo.keyword": "something"
         }
       },
       {
         "term": {
           "bar.keyword": "something_else"
         }
       },
       {
         "term": {
           "baz": 0
         }
       }
     ]
   }
 }
}

```

I would like to just do for each `$field`

```auto
{
 "query": {
   "bool": {
     "filter": [
       {
         "term": {
           "$field": "something"
         }
       }
}

```

---

<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 21, 2019, 5:39am UTC](https://discuss.elastic.co/t/term-matching-without-using-keyword-in-the-field-name/182562/2 "2019-06-21T05:39:10Z")

</div>

Closed on June 21, 2019, 5:39am UTC

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