0

I have an index for user registrations for fast search. I need to implement search by certain fields for each event. (each event has its registrations, but of course, I'm storing them into one index)

I'm trying to search it with these parameters:

'query' => [
     'query_string' => [
          'query' => $query,
              'fields'=> ['name', 'lastName', 'email', ...]
           ],
      ],
 ]

But I also need to specify a term, that it should be searching within registrations for a certain event. I have a keyword field for that in my index: event_id.

How can I add this term (event_id) to the current search request?

PS: Filtered has been removed (replaced by bool, but it doesn't support query_string)

Or would it be better to specify a different index type: _type for each event?

1 Answer 1

2

With bool/filter you can definitely include a query_string and a term query. Try like this:

'query' => [
     'bool' => [
         'filter' => [
             [
                'query_string' => [
                  'query' => $query,
                  'fields'=> ['name', 'lastName', 'email', ...]
                ],
             ],
             [
                'term' => [
                  'event_id' => '123'
                ]
             ]
         ]
     ]
 ]
Sign up to request clarification or add additional context in comments.

4 Comments

I've tried this but it seems like it doesn't affect search results. Doesn't matter what I'm looking for, it gives the same results
How are you sending your query?
Ok, your code seems fine to me. Can you also add the mapping of your registrations index? What makes you think that the results don't change? Can you show one specific query that you're making and a sample document you get that shouldn't match?
it was my mistake. After reviewing my code, I found a bug on my client. It wasn't updating search results for an empty result, so looked like it doesn't search. Thanks a lot for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.