如何在Elasticsearch中匹配搜索查询中的单个单词 [英] How to match a single word from a search query in Elasticsearch

查看:802
本文介绍了如何在Elasticsearch中匹配搜索查询中的单个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个名为complexId的字段,它的值带有特殊字符:fruit/1a.445/2.10.mango.因此,当我搜索类似Complex ID fruit/1a.445/2.10.mango的内容时,我应该能够得到结果.

Lets say I have a field called complexId and it has a value with special characters: fruit/1a.445/2.10.mango. So when I search for something like Complex ID fruit/1a.445/2.10.mango, I should be able to get the result.

我想要的是,我希望弹性搜索匹配这三个词中的至少一个:

What I want is, I want elastic search to match at least one among these 3 words:

1. Complex 
2. ID 
3. fruit/1a.445/2.10.mango

例如:-以下是我的两个文件:

eg:- Below are my two documents:

{
   "name": "Joe",
   "complexId": "fruit/1a.445/2.10.mango"
},
{
   "name": "Matt",
   "complexId": "car/35.6a5/chevy.20"
}

用户搜索类似blah blah blah fruit/1a445/mango blah blah的内容,他应该得到以下结果:

The user searches for something like blah blah blah fruit/1a445/mango blah blah and he should get the below result:

{
   "name": "Matt",
   "complexId": "fruit/1a.445/2.10.mango"
}

我尝试了这个,但是没有给我任何结果:

I tried this but it fails to give me any result:

{
   "query": {
      "bool": {
          "match" : 
          {
              complexId : "blah blah blah fruit/1a.445/2.10.mango blah blah"
          }
      }
   }
}

complexId字段具有标准的分析器.

The field complexId has a standard Analyzer.

任何帮助将不胜感激.

推荐答案

在您的情况下,Standard Analyzer无法正常工作.

A Standard Analyzer would not work in your case.

由于您具有特殊字符,因此在存储到ElasticSearch中时将被忽略.尝试改用whitespace分析器.

Since you are having special characters, it will be ignored while storing into ElasticSearch. Try using the whitespace Analyzer instead.

POST _analyze
{
  "analyzer": "whitespace",
  "text": "blah blah blah fruit/1a.445/2.10.mango blah blah"
}

试用不同的分析仪,找到最适合您需求的分析仪.

Play around with different Analyzers and find the one that is best suited for your needs.

您也可以创建自己的自定义分析器.

You could create your own custom Analyzer as well.

这篇关于如何在Elasticsearch中匹配搜索查询中的单个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆