简体   繁体   English

无法配置弹性搜索

[英]Can't configure elasticsearch

I enter the word "Booking" into the search, and already starting from the 5th result it returns "Cooking", but there are still results with the word "Booking", they contain it in the line.我在搜索中输入单词“Booking”,并且已经从第 5 个结果开始返回“Cooking”,但是仍然有带有单词“Booking”的结果,它们包含在行中。

$this->aQuery['query']['bool']['must'][]['multi_match'] = [
   'type' => 'cross_fields',
   'query' => 'Booking',
   'fields' => ['prod_name', 'prod_prefix'],
   'operator' => 'or'
];

I need results containing only the word "Booking".我需要只包含“预订”一词的结果。 But if you enter "Travel Booking", then the results may contain both "Travel" and "Booking".但如果您输入“Travel Booking”,则结果可能同时包含“Travel”和“Booking”。

To get an exact match, use the term query要获得完全匹配,请使用术语查询

Match uses the, so called, analyzers to transform your search and find all matching words. Match 使用所谓的分析器来转换您的搜索并找到所有匹配的单词。 Terms check for exact match on the search strings, so searching for Booking should not return documents that contain "Travel Booking".条款检查搜索字符串的完全匹配,因此搜索 Booking 不应返回包含“Travel Booking”的文档。

As explained on the page:如页面所述:

By default, Elasticsearch changes the values of text fields during analysis.默认情况下,Elasticsearch 在分析期间会更改文本字段的值。 For example, the default standard analyzer changes text field values as follows:例如,默认标准分析器更改文本字段值如下:

  • Removes most punctuation删除大部分标点符号
  • Divides the remaining content into individual words, called tokens将剩余的内容分成单独的单词,称为标记
  • Lowercases the tokens小写标记

The term query does not analyze the search term.词条查询不分析搜索词条。 The term query only searches for the exact term you provide.术语查询仅搜索您提供的确切术语。 This means the term query may return poor or no results when searching text fields.这意味着在搜索文本字段时,术语查询可能会返回较差的结果或没有结果。

Also note that you need to include a Keyword type in your index mappings另请注意,您需要在索引映射中包含关键字类型

"prod_name": {
    "type":  "text",
    "fields": {
      "raw": { 
        "type":  "keyword"
      }
    }
  }

Then when you search for your word, you need to use the Keyword field name:那么当你搜索你的单词时,你需要使用Keyword字段名:

"term": {
  "prod_name.raw": {
    "value": "Booking",
    "boost": 1.0
  }
}

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

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