Search code examples
lucenequery-parser

searching lucene index on multiple fields


I have an index with 2 content fields (analyzed, indexed & stored):
for example: name , hobbies. (The hobbies field can be added multiple times with different values).

I have another field that is only indexed (un_analyzed & not stored) used for filtering:
for example: country_code

Now, I want to build a query that will retrieve documents that match (as best as possible) to some "search" input field but only such documents where country_code has some exact value.

What would be the most suitable combination query syntax / query parser to use to build such a query.


Solution

  • You can use the following query:

    country_code:india +(name:search_value OR hobbies:search_value)