【问题标题】:Weird results from Elastic search when using a synonym analyzer使用同义词分析器时弹性搜索的奇怪结果
【发布时间】:2020-09-25 20:21:43
【问题描述】:

当我运行这个查询时

"multi_match": {
    "query": "paper copier ", 
    "fields": [ "allStringFields" ],
    "type": "cross_fields",
    "operator": "and",
    "analyzer": "synonym"   
}

我得到 1342 个结果

但是当我运行这个查询时(注意词序)

 "multi_match": {
    "query": " copier paper ", 
    "fields": [ "allStringFields" ],
    "type": "cross_fields",
    "operator": "and",
    "analyzer": "synonym"   
 }

我得到零个结果

我正在使用同义词分析器,这是导致此行为的原因

有解决办法吗?

【问题讨论】:

  • 我的索引定义看起来和你在这里写的很相似,但还是不行。

标签: elasticsearch


【解决方案1】:

添加一个包含索引数据、映射、搜索查询和搜索结果的工作示例。在下面的例子中,我取了两个同义词tabletables

I get zero results

请再次检查您的索引映射。根据下面的示例,搜索关键字是table chair,这将在titlecontent 两个字段中进行搜索。下面的查询将返回同时包含table AND chair 的文档。详细解释请参考Multi match querysynonym token filter上的ES文档。

索引映射:

{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "synonym_filter": {
            "type": "synonym",
            "synonyms": [
              "table, tables"
            ]
          }
        },
        "analyzer": {
          "synonym_analyzer": {
            "filter": [
              "lowercase",
              "synonym_filter"
            ],
            "tokenizer": "standard"
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}

索引数据:

{ "title": "table chair" }
{ "title": "tables chair" }
{ "title": "table fan" }
{ "title": "light fan", "content": "chair" }

搜索查询:

{
    "query": {
        "multi_match": {
            "query": "table chair",
            "operator": "and",
            "type":"cross_fields",
            "fields": [
                "title","content"
            ],
            "analyzer": "synonym_analyzer"
        }
    }
}

搜索结果:

"hits": [
      {
        "_index": "synonym",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.7227666,
        "_source": {
          "title": "table chair"
        }
      },
      {
        "_index": "synonym",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.3862942,
        "_source": {
          "title": "tables chair"
        }
      }
    ]

搜索table chairchair table,得到的搜索结果如上所示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 2018-01-12
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多