Term matching without using keyword in the field name

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?

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

I would like to just do for each $field

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

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