gpt4 book ai didi

filter - Elasticsearch过滤器不适用于字符串过滤器术语

转载 作者:行者123 更新时间:2023-12-02 23:03:01 24 4
gpt4 key购买 nike

对于以下相同的记录,我使用多种方法进行过滤以获取它,但我不知道为什么有些方法可以工作,而有些方法却无法工作。有什么我要担心的吗

   //not work:  
filtered: {
query: {"match_all": {}},
filter: {"term" : { "name": "Road to Rio 2016"}
}

//not work:
filtered: {
query: {"match_all": {}},
filter: {"term" : { "isTemplate": "N"}
}

//work:
filtered: {
query: {"match_all": {}},
filter: {"term" : { "teamId": 147}
}

//work:
filtered: {
query: {"match_all": {}},
filter: {"term" : { "programId": 12615}
}

这是我得到的记录,后两种方式
 "hits": [
{
"_index": "bridge_tracker_cli_v0.0.7",
"_type": "program",
"_id": "12615",
"_score": null,
"_source": {
"programId": 12615,
"sportId": null,
"name": "Road to Rio 2016",
"description": "Program Overview",
"isTemplate": "N",
"editedById": 2170,
"createdById": 1491,
"clonedFromProgramId": 12608,
"teamId": 147,
"organizationId": 117,
"createdAt": "2015-02-26T07:45:50.000Z",
"updatedAt": "2015-04-13T04:47:41.000Z"
},
"sort": [
1424936750000
]
},

下面是记录映射:
 "_all": {
"index_analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},

"properties": {
"clonedFromProgramId": {
"type": "long",
"include_in_all": false
},
"createdAt": {
"type": "date",
"format": "dateOptionalTime",
"include_in_all": false
},
"createdById": {
"type": "long",
"include_in_all": false
},
"createdByScope": {
"type": "string",
"include_in_all": false
},
"dateEdit": {
"type": "date",
"format": "dateOptionalTime",
"include_in_all": false
},
"description": {
"type": "string"
},
"editedById": {
"type": "long",
"include_in_all": false
},
"editedByScope": {
"type": "string",
"include_in_all": false
},
"isTemplate": {
"type": "string"
"include_in_all": false
},
"name": {
"type": "string"
},
"organizationId": {
"type": "long",
"include_in_all": false
},
"programId": {
"type": "long"
},
"updatedAt": {
"type": "date",
"format": "dateOptionalTime",
"include_in_all": false
}
}

下面是分析器:
 "analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 1,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}

最佳答案

如果要对字符串使用术语过滤器,请确保将索引更改为not_analyzed。但是在这种情况下,全文搜索将不适用于该 Realm 。为了确保能同时使用过滤器和全文本搜索,请将此字段更改为多字段。
例如,对于名称,将映射更改为

"name":{
"type": "string",
"fields": {
"not_analyzed":{
"index": "not_analyzed"
}
}
}

并使用name.not_analyzed进行过滤。

关于filter - Elasticsearch过滤器不适用于字符串过滤器术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29744264/

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