elasticsearch - 多字同义词和短语查询

标签 elasticsearch

Elastic文档中有错误吗?

给定以下索引映射:

PUT /my_index
{
  "settings": {
    "analysis": {
      "filter": {
        "my_synonym_filter": {
          "type": "synonym",
          "synonyms": [
            "usa,united states,u s a,united states of america"
          ]
        }
      },
      "analyzer": {
        "my_synonyms": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_synonym_filter"
          ]
        }
      }
    }
  }
}

鉴于此文件:
put /my_index/country/1
{
  "title" : "The United States is wealthy"
}

在文档中指出:

这些词组不匹配:

美国很富有

美国富裕

美国很富有

但是,这些短语将:

美国富裕

美国富国

美国的富人

美国是美国

但是,似乎并非如此-应该匹配的短语根本不匹配!这是我正在运行的查询(根据documentation在查询时没有同义词扩展):
GET /my_index/country/_search
{

    "query" : {
        "match_phrase" : {
            "title" : {
               "query" : "United States is wealthy",
               "analyzer": "standard"
            }

        }
    }
}

我在这里想念什么?

最佳答案

文档中的示例对我有用。

您可能忘记了为映射中的title字段设置分析器。

例:

1)创建索引

PUT /my_index
{
  "settings": {
    "analysis": {
      "filter": {
        "my_synonym_filter": {
          "type": "synonym",
          "synonyms": [
            "usa,united states,u s a,united states of america"
          ]
        }
      },
      "analyzer": {
        "my_synonyms": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_synonym_filter"
          ]
        }
      }
    }
  }
}

2)添加映射
PUT my_index/country/_mapping
{
    "properties" : {
        "title" : {"type" : "string","analyzer" : "my_synonyms"}
    }
}

3)索引文件
PUT /my_index/country/1
{
  "title" : "The United States is wealthy"
}

4)查询
GET /my_index/country/_search
{

    "query" : {
        "match_phrase" : {
            "title" : {
               "query" : "United States is wealthy",
               "analyzer": "standard"
            }

        }
    }
}

5)回应:
{
   "took": 8,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.75942194,
      "hits": [
         {
            "_index": "my_index",
            "_type": "country",
            "_id": "1",
            "_score": 0.75942194,
            "_source": {
               "title": "The United States is wealthy"
            }
         }
      ]
   }
}

关于elasticsearch - 多字同义词和短语查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32126226/

相关文章:

elasticsearch - 在ElasticSearch中按多个字段搜索确切短语

spring - 过滤器嵌套数组 Spring elasticsearch

indexing - ElasticSearch 索引 Confluence 页面

elasticsearch - Elasticsearch river-5次尝试后未找到_meta文档

Elasticsearch : Curator does not work

elasticsearch - Logstash 文件名作为 ElasticSearch 索引

javascript - react : Uncaught TypeError: Cannot read property 'setState' of undefined

elasticsearch - 如何标记从 Neo4j 复制到 Elastic 搜索的数据?

elasticsearch - 使用Elastic Common Schema配置基于Filebeat提示的自动发现

mysql - 多用途搜索如何与 Searchkick 配合使用?