简体   繁体   English

在ElasticSearch中使用指定术语查询字符串

[英]Query string with specifying term in ElasticSearch

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 . 我在索引中有一个关键字字段: event_id

How can I add this term (event_id) to the current search request? 如何将此词(event_id)添加到当前搜索请求中?

PS: Filtered has been removed (replaced by bool , but it doesn't support query_string ) PS: 筛选已删除(已替换为bool ,但不支持query_string

Or would it be better to specify a different index type: _type for each event? 还是为每个事件指定不同的索引类型: _type更好?

With bool/filter you can definitely include a query_string and a term query. 使用bool/filter您绝对可以包含query_stringterm查询。 Try like this: 尝试这样:

'query' => [
     'bool' => [
         'filter' => [
             [
                'query_string' => [
                  'query' => $query,
                  'fields'=> ['name', 'lastName', 'email', ...]
                ],
             ],
             [
                'term' => [
                  'event_id' => '123'
                ]
             ]
         ]
     ]
 ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM