gpt4 book ai didi

elasticsearch - Elasticsearch 全字符串匹配不起作用

转载 作者:行者123 更新时间:2023-12-02 22:34:15 25 4
gpt4 key购买 nike

我正在使用Elastic builder npm
使用esb.termQuery(Email, "test")对应:

"CompanyName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
数据库字段:
"Email": "test@mycompany.com",
"CompanyName": "my company"
查询JSON: { term: { CompanyName: 'my' } }。或 { term: { Email: 'test' } }结果:
"Email": "test@mycompany.com",
"CompanyName": "my company"
期望:
没有结果,需要全文匹配,此处的Match就像“like”或queryStringQuery。
我有3个过滤器前缀,完全匹配,包括。

最佳答案

The standard analyzer is the default analyzer which is used if none isspecified. It provides grammar based tokenization


在您的示例中,也许您没有在索引映射中显式指定任何分析器,因此默认情况下将分析文本字段,而标准分析器是它们的默认分析器。
请引用此SO answer以获得对此的详细说明。

如果未定义分析器,则会生成以下标记。
POST/_analyze 

{
"analyzer" : "standard",
"text" : "test@mycompany.com"
}
token 是:
{
"tokens": [
{
"token": "test",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "mycompany.com",
"start_offset": 5,
"end_offset": 18,
"type": "<ALPHANUM>",
"position": 1
}
]
}
如果要全文搜索,则可以使用小写过滤器定义自定义分析器,小写过滤器将确保在对文档建立索引并进行搜索之前,将所有字母都更改为小写。

The normalizer property of keyword fields is similar to analyzerexcept that it guarantees that the analysis chain produces a singletoken.

The uax_url_email tokenizer is like the standard tokenizer except thatit recognises URLs and email addresses as single tokens.


索引映射:
{
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
},
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "uax_url_email"
}
}
}
},
"mappings": {
"properties": {
"CompanyName": {
"type": "keyword",
"normalizer": "my_normalizer"
},
"Email": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
索引数据:
{
"Email": "test@mycompany.com",
"CompanyName": "my company"
}
搜索查询:
{
"query": {
"bool": {
"should": [
{
"match": {
"CompanyName": "My Company"
}
},
{
"match": {
"Email": "test"
}
}
],
"minimum_should_match": 1
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64220291",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"Email": "test@mycompany.com",
"CompanyName": "my company"
}
}
]

关于elasticsearch - Elasticsearch 全字符串匹配不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64220291/

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