- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
更新 :
在阅读了 Richa 的解释和推荐的 blog post 后,该问题似乎已得到解决。 ,但我需要更多测试才能确认。
首先,应按照 Richa 的建议更改同义词格式:
[“绿色 => 卡其色,绿色”,“宠物 => 猫,宠物”]
然后,我必须指定 search_analyzer
和 index_analyzer
在索引映射中:
"mappings": {
"properties": {
"phone_case": {
"type": "text",
"norms": false,
"index_analyzer": "standard",
"search_analyzer": "lowercaseWhiteSpaceAnalyzer"
}
}
}
analyzer
在查询中。
[ "khaki => khaki,green", "cat => cat,pet"]
{
settings: {
"analysis": {
"char_filter": {
"same_word": {
"type": "mapping",
"mappings": ["-=>", "&=>and"]
},
},
"filter": {
"my_stopwords": {
"type": "stop",
"stopwords": STOPWORD_FILE
},
"my_synonym": {
"type": "synonym",
"synonyms": [ "khaki => khaki,green", "cat => cat,pet"],
"tokenizer": "whitespace"
},
},
"analyzer": {
"lowercaseWhiteSpaceAnalyzer": {
"type": "custom",
"char_filter": ["html_strip", "same_word"],
"tokenizer": "standard",
"filter": [
"lowercase",
"my_stopwords",
"my_synonym",
]
},
}
}
}
}
"phone_case":{"type":"text","norms":false,"analyzer":"lowercaseWhiteSpaceAnalyzer"}
[
{
id: "1",
phone_case: "khaki,brushed and polished",
},
{
id: "2",
phone_case: "green,brushed",
},
{
id: "3",
phone_case: "black,matte"
}
]
{
"sort": [
{
"updated": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"query": {
"bool": {
"filter": {
"term": {
"phone_case": "khaki"
}
}
}
}
{
"sort": [
{
"updated": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"query": {
"match_phrase": {
"phone_case": "khaki"
}
}
}
最佳答案
根据 elastic documentation , 当我们定义我们的同义词时,如 a => b,c
, 即解决为
# Explicit mappings match any token sequence on the LHS of "=>"
# and replace with all alternatives on the RHS. These types of mappings
# ignore the expand parameter in the schema.
"khaki => khaki,green"
, 字
khaki
将替换为
khaki
和
green
.这可以使用
analyze
查看。 api之类的
GET stack-57703209/_analyze
{
"text": "khaki",
"analyzer": "lowercaseWhiteSpaceAnalyzer"
}
khaki
和
green
.
{
"tokens" : [
{
"token" : "khaki",
"start_offset" : 0,
"end_offset" : 5,
"type" : "SYNONYM",
"position" : 0
},
{
"token" : "green",
"start_offset" : 0,
"end_offset" : 5,
"type" : "SYNONYM",
"position" : 0
}
]
}
green
GET stack-57703209/_analyze
{
"text": "green",
"analyzer": "lowercaseWhiteSpaceAnalyzer"
}
green
.
{
"tokens" : [
{
"token" : "green",
"start_offset" : 0,
"end_offset" : 5,
"type" : "<ALPHANUM>",
"position" : 0
}
]
}
"green => khaki,green"
not "khaki => khaki,green"
index
应用此分析器。时间。因此,在索引您的文档时,
khaki
这个词替换为
khaki
和
green
正如我们在上面使用分析 api 看到的那样。
Term Query
, 搜索确切的词
{
"sort": [
{
"updated": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"query": {
"bool": {
"filter": {
"term": {
"phone_case": "khaki"
}
}
}
}
khaki
,您只会得到第一个响应结果,因为 Term Query 不应用任何搜索分析器并匹配确切的术语,因此它会查找
khaki
第二个文档是
phone_case: "green,brushed",
没有带有
khaki
的 token (可以使用分析 api 进行检查),因此不会返回。
index analyzer
相同的分析器默认情况下,在您的情况下
lowercaseWhiteSpaceAnalyzer
.所以这两个文件都被退回了。
search analyzer
而不是
index analyzer
, 因此您可以将索引设置更改为
{
"settings": {
"analysis": {
"char_filter": {
"same_word": {
"type": "mapping",
"mappings": [
"-=>",
"&=>and"
]
}
},
"filter": {
"my_stopwords": {
"type": "stop",
"stopwords": "a, an"
},
"my_synonym": {
"type": "synonym",
"synonyms": [
"green => khaki,green", //NOTE THIS
"cat => cat,pet"
],
"tokenizer": "whitespace"
}
},
"analyzer": {
"lowercaseWhiteSpaceAnalyzer": {
"type": "custom",
"char_filter": [
"html_strip",
"same_word"
],
"tokenizer": "standard",
"filter": [
"lowercase",
"my_stopwords"
]
},
"synonym_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"my_synonym"
]
}
}
}
},
"mappings": {
"properties": {
"phone_case": {
"type": "text",
"norms": false,
"analyzer": "lowercaseWhiteSpaceAnalyzer"
}
}
}
}
search analyzer
相反,像
{
"query": {
"match_phrase": {
"phone_case" : {
"query" : "green",
"analyzer" : "synonym_analyzer" // NOTE THIS
}
}
}
}
关于node.js - match_phrase 不适用于 Elasticsearch 中的同义词标记过滤器(类型扩展),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57703209/
我正在寻找一种方法来实现具有同义词和模糊性的自动建议 例如,当用户试图搜索“replce ar”时我的同义词列表有 ar => 录音 所以,结果应该包括匹配的项目改变录音更换录音等等, 这里我们需要模
我在 Pandas 中有两列:A 和 B,每列都包含术语字符串。我的目标是在 B 列中找到与 A 列最相似的条目。我已经在使用 TF-IDF 来执行此操作,但有时存在不明显匹配的同义词,例如货币和货币
通过 Oracle 查询是否可以找出存储过程使用哪些 View /同义词/表? 在 PL/SQL Developer 中,如果您折叠存储过程,它将显示“引用”,其中显示了存储过程使用的所有表/ Vie
我正在阅读这篇文章: Managing Oracle Synonyms 关于优先顺序,在将对象名称解析为实际对象时,它说: 本地对象总是首先被访问。 如果本地对象不存在,则将访问具有私有(privat
这是一个非常愚蠢的问题,但我需要帮助。 我有一张 mydbowner 拥有的 table 。它被命名为 mydbowner.mytable。我试图通过发出命令来创建一个公共(public)同义词: 为
我用同义词标记过滤器创建了一个测试索引 PUT /synonyms-index { "settings": { "analysis": { "filter": { "my_synonym_filte
故事:给定下面的示例文档并通过扩展它们,有可能获得以下排名: 对“ Cereal ”的搜索结果显示以下排名 Jade 米片 水稻脆饼 搜索“大米”会得出以下排名 印度香米 水稻脆饼 执行针对搜索的文档
背景: 一直以来,我一直认为,如果同义词文件中有任何更改,您将需要重新索引整个索引。当然,如果索引大小很小,过程不会那么慢,但是过程本身很乏味,并且会有停机时间。 所以问题: 在这种情况下,我的理解有
我正在尝试将给定单词的同义词存储到HashMap中。然后,我接受用户输入并检查它是否是一个单词或其同义词。例如,假设主要词是“bank”,其同义词是“safe”、“tresury”和“credit u
我有一个名为“unittest”的 Ant 目标,我觉得它很笨重,我想改用“test”。我需要保留名称“unittest”,因为其他人也使用 ant 构建文件。 有没有办法为特定目标添加别名或同义词?
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
是否可以在索引中存储elasticsearch的同义词?或者是否可以从像 couchdb 这样的数据库中获取同义词列表?我想通过 REST-API 向 elasticsearch 动态添加同义词。 最
我如何从订单表中返回员工 ID 和每个员工处理的订单总数,并将总数从大到小排序。 最佳答案 使用 GROUP BY 计算每个员工的订单数量,并使用 ORDER BY 对结果进行排序。 SELECT e
我曾经使用 Solr,它会有包含停用词、同义词等文件的配置文件夹。每次进行更改时,您都可以使用 Zookeeper 下载 conf 文件,然后将其上传并分发到集群中的所有服务器。 ElasticSea
您好,我正在寻找问题的解决方案:我想找到与法语和英语相似的单词列表例如 :名字可以是:名字、姓氏、化名、普雷诺姆、用户名......邮政地址可以是:城市、国家、街道、维尔、付款、邮政编码......
我在自定义文件中使用同义词标记过滤器 在Windows 10计算机上将Elasticsearch 6.7安装为服务 我的同义词。txt位于C:\ProgramData\Elastic\Elastics
我正在将Ruby on Rails与elasticsearch-rails gem一起使用,并且尝试使用同义词过滤器。我一直在关注此处发布的问题以寻求指导(我的实现按预期工作,但同义词部分除外): h
我正在尝试学习如何将“同义词功能”正确添加到我现有的 ElasticSearch 设置中。到目前为止,这是我对这个过程的理解。如果您能指出我的任何误解,我将不胜感激 - 我是 elasticsearc
我正在使用 Mybatis 生成器生成对象。我能够在该模式中生成具有实际表名的类。但授予该表上不同模式的选择权限并创建了一个私有(private)同义词。我想使用该同义词生成对象。
我正在使用 python 2.7,我正在尝试使用阿拉伯语 WordNet 获取阿拉伯语单词的同义词 我下载了两个需要的文件: AWNDatabaseManagement.pyupc_db.xml 当我
我是一名优秀的程序员,十分优秀!