【问题标题】:Elasticsearch: Unable to search with wordformsElasticsearch:无法使用单词形式进行搜索
【发布时间】:2016-01-09 09:12:57
【问题描述】:

我正在尝试设置 Elasticsearch,创建索引,添加一些记录,但无法使其返回带有单词形式的结果(例如:当我搜索“dream”时,带有子字符串“dreams”的记录)。

我的记录如下所示(索引“myindex/movies”):

{
    "id": 1,
    "title": "What Dreams May Come",
    ... other fields
}

我尝试使用的配置:

{
    "settings": {
        "analysis": {
            "analyzer": {
                "stem": {
                    "tokenizer": "standard",
                    "filter": [
                        "standard",
                        "lowercase",
                        "stop",
                        "porter_stem"
                    ]
                }
            }
        }
    },
    "mappings": {
        "movies": {
            "dynamic": true,
            "properties": {
                "title": {
                    "type": "string",
                    "analyzer": "stem"
                }
            }
        }
    }
}

查询看起来像这样:

{
    "query": {
        "query_string": {
            "query": "Dream"
        }
    }
}

我可以使用单词“dreams”而不是“dream”来获得结果。

我做错了吗? 我应该先安装 porter_stem 吗?

【问题讨论】:

    标签: elasticsearch search nosql


    【解决方案1】:

    你没有做错什么,只是你在错误的领域搜索。 query_string ,默认在 _all 上进行搜索。 _all 有自己的分析器。 因此,您要么需要对 _all 应用相同的分析器,要么将查询指向标题字段,如下所示 -

    {
      "query": {
        "query_string": {
          "query": "dream",
          "default_field": "title"
        }
      }
    }
    

    【讨论】:

    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多