ElasticSearch edgeNGram [英] ElasticSearch edgeNGram

查看:488
本文介绍了ElasticSearch edgeNGram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置和分析器:

I have the following settings and analyzer:

put /tests
{
"settings": {
    "analysis": {
         "analyzer": {
             "standardWithEdgeNGram": {
                 "tokenizer": "standard",
                 "filter": ["lowercase", "edgeNGram"]
             }
         },
         "tokenizer": {
             "standard": {
                 "type": "standard"
             }
         },
         "filter": {
             "lowercase": {
                "type": "lowercase"
            },
            "edgeNGram": {
                "type": "edgeNGram",
                "min_gram": 2,
                "max_gram": 15,
                "token_chars": ["letter", "digit"]
            }
        }
    }
},
"mappings": {
    "test": {
        "_all": {
            "analyzer": "standardWithEdgeNGram"
        },
        "properties": {
            "Name": {
                "type": "string",
                "analyzer": "standardWithEdgeNGram"
            }
        }
   }
}
}

我发布了以下数据:

POST /tests/test
{
    "Name": "JACKSON v. FRENKEL"
}

这里是我的查询:

GET /tests/test/_search
{
    "query": {
        "match": {
           "Name": "jax"
        }
    }
}

这个结果:

{
    "took": 2,
    "timed_out": false,
    "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
},
"hits": {
    "total": 1,
    "max_score": 0.19178301,
    "hits": [
        {
            "_index": "tests",
            "_type": "test",
            "_id": "lfOxb_5bS86_CMumo_ZLoA",
            "_score": 0.19178301,
            "_source": {
                "Name": "JACKSON v. FRENKEL"
            }
        }
    ]
}
}



<有人可以向我解释说,名字中的任何地方都没有jax,还会得到匹配?

Can someone explain to me that there is no "jax" anywhere in the "Name", and it still gets the match?

提前感谢

推荐答案

A match 查询对其给定值执行分析。默认情况下,jax正在使用 standardWithEdgeNGram 进行分析,其中包括将n-gram分析置换为 [ja,ax] ,其中第一个匹配ja >JACKSON v。FRENKEL。

A match query performs analysis on its given value. By default, "jax" is being analyzed with standardWithEdgeNGram, which includes n-gram analysis permuting it into ["ja", "ax"], the first of which matches the "ja" from the analyzed "JACKSON v. FRENKEL".

如果您不想要此行为,您可以将不同的分析器指定为匹配,使用分析器字段,例如 关键字

If you don't want this behavior you can specify a different analyzer to match, using the analyzer field, for example keyword:

GET /tests/test/_search
{
    "query": {
        "match": {
           "Name": "jax",
           "analyzer" : "keyword"
        }
    }
}

这篇关于ElasticSearch edgeNGram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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