gpt4 book ai didi

elasticsearch - 匹配特定字段,但不匹配_all(ES 1.7)

转载 作者:行者123 更新时间:2023-12-02 23:29:37 26 4
gpt4 key购买 nike

当我运行此搜索时,我会得到我期望的记录:

POST users/user/_search
{"query":{"match":{"name":"smi"}}}

产量:
{
"took": 3,
"timed_out": false,
"_shards": { "total": 5, "successful": 5, "failed": 0 },
"hits": {
"total": 1,
"max_score": 0.8838835,
"hits": [
{
"_index": "users",
"_type": "user",
"_id": "648398826796745835",
"_score": 0.8838835,
"_source": {
"email": "jonsmith@j.smith.enterprises",
"name": "Jon Smith",
"username": "jonsmith",
"first_name": "Jon",
"last_name": "Smith",
"image_url": "blahblahblah"
}
}
]
}
}

但是,当我运行类似的搜索(希望它也能正常运行)时,我什么也没得到:
POST users/user/_search
{"query":{"match":{"_all":"smi"}}}

产量:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

映射非常简单:
GET users/_mapping/user

{
"users": {
"mappings": {
"user": {
"properties": {
"email": { "type": "string", "analyzer": "our_email" },
"email_username": { "type": "string", "analyzer": "email_username" },
"first_name": { "type": "string", "analyzer": "our_name" },
"image_url": { "type": "string", "index": "not_analyzed" },
"last_name": { "type": "string", "analyzer": "our_name" },
"name": { "type": "string", "analyzer": "our_name" },
"username": { "type": "string", "analyzer": "our_name" }
}
}
}
}
}
our_name分析器是这样实现的,尽管我在1.7 API中找不到在分析器配置上进行GET的方法:
{
"analysis": {
"analyzer": {
"our_name": {
"filter": [
"lowercase",
"word_delimiter",
"our_edgeNgram25"
],
"tokenizer": "standard"
}
},
"filter": {
"our_edgeNgram25": { "max_gram": 5, "min_gram": 2, "type": "edgeNGram" },
"our_email_filter": {
"patterns": [ "(.+)@(.+)" ],
"type": "pattern_capture"
}
}
}
}

在user.name字段上运行演示分析使我认为它应该按原样匹配:
GET users/_analyze?analyzer=our_name&text=jon%20smith
{
"tokens": [
{
"token": "jo",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 1
},
{
"token": "jon",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 1
},
{
"token": "sm",
"start_offset": 4,
"end_offset": 9,
"type": "word",
"position": 2
},
{
"token": "smi",
"start_offset": 4,
"end_offset": 9,
"type": "word",
"position": 2
},
{
"token": "smit",
"start_offset": 4,
"end_offset": 9,
"type": "word",
"position": 2
},
{
"token": "smith",
"start_offset": 4,
"end_offset": 9,
"type": "word",
"position": 2
}
]
}

意见表示赞赏,谢谢。

最佳答案

_all默认使用标准分析器,因此您无法找到子字符串,请在映射中为_all指定分析器

关于elasticsearch - 匹配特定字段,但不匹配_all(ES 1.7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37927323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com