一尘不染

ElasticSearch edgeNGram

elasticsearch

我具有以下设置和分析器:

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”,但仍然可以匹配吗?

提前致谢


阅读 268

收藏
2020-06-22

共1个答案

一尘不染

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

如果您不希望出现这种情况,则可以match使用analyzer字段将其他分析器指定为,例如keyword

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