弹性搜索:与分析仪匹配查询不起作用 [英] Elastic search : Match query with analyzer is not working

查看:310
本文介绍了弹性搜索:与分析仪匹配查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的目标是搜索一个词,无论添加了分析器。

My goal is to search a word irrespective of the analyzer added to that.

我用过匹配查询与关键字分析器,但我认为它可以与默认分析器添加到该属性。

I used match query with keyword analyzer but i think it works with the default analyzer added to that property.

在弹性搜索,我的作者文档结构就像

In elastic search, my author document structure is like

"_source": {
               "Id": 3,
               "Organization": "let123"
            }

索引映射:

 createIndexDescriptor.NumberOfReplicas(1)
                .NumberOfShards(1)
                .Settings(
                    settings =>
                    settings
                        .Add("analysis.filter.autocomplete_filter_ngram.type", "edge_ngram")
                        .Add("analysis.filter.autocomplete_filter_ngram.min_gram", "2")
                        .Add("analysis.filter.autocomplete_filter_ngram.max_gram", "7")
                        .Add("analysis.analyzer.title_analyzer.type", "custom")
                        .Add("analysis.analyzer.title_analyzer.char_filter.0", "html_strip")
                        .Add("analysis.analyzer.title_analyzer.tokenizer", "standard")
                        .Add("analysis.analyzer.title_analyzer.filter.0", "lowercase")
                        .Add("analysis.analyzer.title_analyzer.filter.1", "asciifolding")
                        .Add("analysis.analyzer.title_analyzer.filter.2", "autocomplete_filter_ngram"))
                .AddMapping<Author>(
                    m =>
                    m.MapFromAttributes()
                        .AllField(f => f.Enabled(true))
                        .Properties(
                            props =>
                            props.MultiField(
                                mf =>
                                mf.Name(t => t.Organization)
                                    .Fields(fs => fs.String(s => s.Name(t => t.Organization).Analyzer("title_analyzer"))
                                          ))));




这里我注意到我的一个标题分析器过滤器是 ngram

但是我在匹配查询中使用了关键字分析器,以避免在我的搜索中自动填充。

But I used keyword analyzer in my match query to avoid autocomplete in my searching.

GET /author/_search {
    "query": {
        "match": {
           "Organization": {
               "query": "le",
               "analyzer": "keyword"
           }
        }
    } }

但是当我搜索时,上面的文档是匹配的。
我期待的是组织的确切值为 le

But when i searched, the above document is matched. what i am expecting is Organization having exact value as 'le'

为什么这匹配?任何想法实现我的目标?

Why this is matched? Any idea to achieve my goal?

推荐答案

通过在查询中指定分析器,您正在指示Elasticsearch如何分析您的查询,已发送。

By specifiying the analyser in the query you are instructing Elasticsearch how to analyse the query you've sent.

例如:

GET /author/_search {
    "query": {
        "match": {
           "Organization": {
               "query": "le",
               "analyzer": "keyword"
           }
        }
    } }

告诉弹性搜索使用关键字分析器在 le 字符串。它不会影响已存储数据已创建的索引条款( let123

Tells Elasticsearch to use the keyword analyser on the le string. It doesn't affect the indexed terms that have already been created on your stored data (let123)

唯一的更改存储数据分析方式的方法是更新您的映射并重新编制数据。

The only way to change the way that stored data is analysed, is to update your mapping and re-index your data.

对于相同的字段,不可能有多个分析器,但数据可以容易地存储在多个字段中(每个都有一个分析器)。

It's not possible to have multiple analyzers against the same field but data can instead be easily stored in multiple fields (each having a single analyser).



for example:

{
  "tweet" : {
    "properties" : {
      "name" : {
        "type" : "string",
        "index" : "analyzed",
        "fields" : {
          "raw" : {"type" : "string", "index" : "not_analyzed"}
        }
      }
    }
  }
}

名称数据自动存储在两个位置 - 在名称(分析的位置)和 name.raw (不进行分析)。请参阅多字段

the name data is automatically stored in two places - in fields name (where it is analysed) and name.raw (where no analysis takes place). See Multi Fields.

这篇关于弹性搜索:与分析仪匹配查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆