首页 \ 问答 \ 在elasticsearch中搜索不返回T恤的T恤(Searching for T-shirt not returning t-shirt in elasticsearch)

在elasticsearch中搜索不返回T恤的T恤(Searching for T-shirt not returning t-shirt in elasticsearch)

我正在使用elasticSearch的以下设置和映射

{
  "settings": {
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 10
        },
        "synonym_filter": {
          "type": "synonym",
          "synonyms":[
            "yoga,fit-sports,blue",
            "tshirt,tees,t-shirt "
          ]
        }
      },
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase",
            "synonym_filter",
            "autocomplete_filter"
          ]
        }
      }
    }
  },
  "mappings": {
    "products": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          },
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
      }
    }
  }
}

我把一个字段“名称:公主打印T恤”编入索引。

在使用空白分析器时,可以创建“T恤”之类的标记。 但搜索我使用“search_analyzer”:“标准”查询我认为是像“公主印花T恤”和这个“T恤”不匹配,因此会给空的搜索结果。 我的一个解决方案就像添加“T恤,T恤”这样的同义词。 然后我会得到结果。 但在这种情况下,如果我们搜索“衬衫”,它将返回“T恤和衬衫”,这是不可接受的。 如果我没有使用这个“search_analyzer”:“标准”我没有得到预期的结果。 如果我搜索“T恤”,我只需要搜索结果


I am using the following settings and mappings for elasticSearch

{
  "settings": {
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 10
        },
        "synonym_filter": {
          "type": "synonym",
          "synonyms":[
            "yoga,fit-sports,blue",
            "tshirt,tees,t-shirt "
          ]
        }
      },
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase",
            "synonym_filter",
            "autocomplete_filter"
          ]
        }
      }
    }
  },
  "mappings": {
    "products": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          },
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
      }
    }
  }
}

And I indexed a field "name:Princess Print T-shirt".

As am using whitespace analyzer, es create token like "t-shirt". but for searching i am using "search_analyzer": "standard" the query i think is going like "princess print t shirt" and this "t shirt" will not match thus will give empty search result. One solution from my side is like adding synonym like "t shirt,t-shirt". Then i will get the result. but in this case if we search for "shirt" it will return both "t-shirt and shirt" which is not acceptable. And if i didn't use this "search_analyzer": "standard" i am not getting expected result. If i search for "t-shirt" i need only tat search result


原文:https://stackoverflow.com/questions/49514491
更新时间:2019-07-04 03:12

最满意答案

问题描述

有问题的部分是你已经描述过的"search_analyzer": "standard"

这将把T-shirt每一个入口都转换成令牌tshirt 。 索引中的数据看起来像t-shirtt-shir等等,并且不匹配。

可能的方案

调整搜索分析器

您需要确保查询是小写的,以空格分隔。 因此,您可以使用whitespace analyzer https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-whitespace-analyzer.html与小写字母分析器结合来定义查询时间的自定义分析器。


Problem description

The problematic part is as you already described "search_analyzer": "standard".

This will transform every entry of T-shirt to the tokens t and shirt. The data in your index looks like t-shirt, t-shir and so on and does not match.

Possible solution

Adapt search analyzer

You need to make sure that the query is lowercased, splitted at whitespace. So you could define also a custom anlyzer for query time using the whitespace analyzer https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-whitespace-analyzer.html combined with a lowercase-analyzer.

2018-03-27

相关问答

更多

ElasticSearch NEST客户端不返回结果(ElasticSearch NEST client not returning results)

NEST试图猜测类型和索引名称,在你的情况下它会使用/ blog / blogentries 因为你告诉默认索引是和blogentries因为它会将小写和复数形式名称传递给Search<T> 。 你可以控制这样的类型和索引: .Search<BlogEntry>(s=>s.AllIndices().Query(...)); 这会让NEST知道你实际上想要在所有索引上搜索,所以nest会将它翻译成根目录上的/_search ,等于你在curl上发布的命令。 你最想要的是: .Search<Bl ...

按要求改寫句子

1:Mr Wang doesn't send his son to school at 7.00 every morning. 2:Are you going to design a red cotton jumper?--Yes, I am. 3:What is Helen's favourite colour? 4:How long is the trip? 5:How does that T-shirt look like on Daniel? 6:Don't forget to close ...

保护弹性搜索(Securing elasticsearch)

有一篇关于保护Elasticsearch的文章,其中包含了很多要注意的要点: http : //www.found.no/foundation/elasticsearch-security/ (完全披露:我写了它并为Found工作) 你还应该知道一些事情: http : //www.found.no/foundation/elasticsearch-in-production/ 总结一下总结: 目前,Elasticsearch并不认为安全性是其工作。 Elasticsearch没有用户的概念。 从 ...

Elasticsearch启动不起来啊

ElasticSearch启动错误处理方法 在配置完elasticsearch,启动程序会包如下错误: 1、针对错误[1]、[2],可以采取如下方式:  修改/etc/security/limits.conf配置文件: [root@yqtrack-elk03 /]# vim /etc/security/limits.conf 添加如下配置项: * - nproc 65535 * - nofile 409600 elastic - memlock unlimited  修改/etc/security ...

ElasticSearch如何与Mysql集成(ElasticSearch how to integrate with Mysql)

从ES 5.x开始,他们已经使用logstash插件提供了该功能。 这将定期从数据库导入数据并推送到ES服务器。 一个人必须创建一个简单的导入文件( 这里也有描述),并使用logstash来运行脚本。 Logstash支持按计划运行此脚本。 # file: contacts-index-logstash.conf input { jdbc { jdbc_connection_string => "jdbc:mysql://localhost:3306/mydb" ...

Logstash无法通过readonly rest elasticsearch插件与elasticsearch进行通信。(Logstash can't communicate with elasticsearch through readonly rest elasticsearch plugin.)

在logstash配置文件中提及输出,如下所示: - output { elasticsearch { hosts => ["localhost:9200"] user => ["logstash"] password => ["logstash"] } Mention output in logstash config file like below :- output { elasticsearch { ...

Spring Boot Elasticsearch配置(Spring Boot Elasticsearch Configuration)

删除你的配置类和属性。 添加以下依赖项 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> 只需将spring.data.elasticsearch属性添加到application-prod.properties和application-dev.properties ...

ElasticSearch映射不起作用(ElasticSearch mapping doesn't work)

要使用特定于字段的分析器,您需要在查询中指定该字段。 否则,使用默认分析仪。 尝试 curl -XGET 'localhost:9200/twitter/_search?q=message:fight' 要么 curl -XGET 'localhost:9200/twitter/_search?df=message&q=looking' To use a field-specific analyzer you need to specify this field in the query. O ...

相关文章

更多

最新问答

更多
  • Android宽度:100%修复(网站接管问题)(Android width:100% fix (website takeover issue))
  • C ++函数/方法设计的良好实践(Good practice in C++ function/method design)
  • 计算其他表中不存在的所有记录 - SQL查询(Count all records that does not exist to other table - SQL Query)
  • 为什么我要用JPA共享ID?(Why do I get shared Ids with JPA?)
  • asp.net - 如何显示来自html格式的数据行的字段(asp.net - how to display a field from data row that is in html format)
  • 我们如何使用ActiveRecord从连接表中删除行?(How can we delete rows from a join table by using ActiveRecord?)
  • ng-class搞乱了类的顺序(ng-class messing with the order of classes)
  • oracle 12g无效数字错误(oracle 12g invalid number error)
  • 更改ng-src值onclick(Change ng-src value onclick)
  • 如何在android中自动添加自定义依赖项以创建新项目?(How to add custom dependencies automatically in android for ever a new project is created?)
  • datetime函数在PHP中(datetime function in php)
  • 在javascript中获取会话数组的值(in javascript get the value of a session array)
  • 如何在UTF8中编译LaTeX?(How can I compile LaTeX in UTF8? [closed])
  • Rspec:“array.should == another_array”,但不用担心订单(Rspec: “array.should == another_array” but without concern for order)
  • Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)
  • JavaFX的。(JavaFX. Adding items to the list in different threads is not working)
  • 从GDATA日历资源迁移到Google Calendar Resource api(Migrate from GDATA calendar resource to Google Calendar Resource api)
  • SSRS 2008 - 以零情景处理分割(SSRS 2008 - Dealing with division by zero scenarios)
  • 我如何以编程方式添加一个listView列标题的点击事件(How can I add a listView column header a click event programmatically)
  • Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)
  • 使用Tortoise SVN在SVN存储库中移动目录(Move Directory across SVN repository using Tortoise SVN)
  • 天蓝色服务结构集群中的web api无状态服务是否在一段时间不活动后进入休眠状态?(Do web api stateless services in azure service fabric cluster go to sleep after a period of inactivity?)
  • 我可以设置intelliJ来突出显示PHP编码风格吗?(Can I set intelliJ to highlight php coding style?)
  • 用javafx创建一个Truetype字体文件(Creating a Truetype Font file with javafx)
  • Spring ftp配置错误(Spring ftp configuration is wrong)
  • 使用gsub去除多个字符(Using gsub to strip multiple characters)
  • 续订推送证书并保持当前的App Store App正常工作(Renew Push certificate and keep current App Store App working)
  • js:ES5和ES6之间关于'this'关键字用法的一个令人困惑的观点(js: one confusing point about 'this' keyword usage between ES5 and ES6)
  • window.onload vs $(document).ready()(window.onload vs $(document).ready())
  • 在Swift中,如何声明一个符合一个或多个协议的特定类型的变量?(In Swift, how can I declare a variable of a specific type that conforms to one or more protocols?)