0

I use php client of elastic search.

I elastic search I want to query multiple fields in the same time, but I want to search for exact match for my_field_2

'query' => [
    'dis_max' => [
    'queries' => [
        ['term' => ['my_field' => 'my_value']],
        ['term' => ['my_field_2' => 'my_value_2']]
    ]
]
]

I tried to add double quote around my_value_2:

['term' => ['my_field_2' => '"my_value_2"']]

How can I ensure to get only exact value for the second field?

tolga
  • 2,462
  • 4
  • 31
  • 57
  • 1
    Does this answer your question? [Exact match in elastic search query](https://stackoverflow.com/questions/37894448/exact-match-in-elastic-search-query) – Markus Zeller Jul 20 '22 at 14:43

1 Answers1

0

If you have not defined the mapping yourself, than Elasticsearch will create a .keyword field for every text field for exact search and agss use-cases. you can simply use the my_field_2.keyword in your search query in this case,

otherwise, you will have to define the keyword field in your mapping and than use it in your search query in order to do the exact search.

Amit
  • 30,756
  • 6
  • 57
  • 88