gpt4 book ai didi

search - Elasticsearch 小写过滤搜索

转载 作者:行者123 更新时间:2023-11-29 02:44:43 32 4
gpt4 key购买 nike

我正在尝试搜索我的数据库并能够使用大写/小写过滤条件,但我注意到当query 应用分析器时,我不知道如何应用过滤搜索中的小写分析器。这是查询:

{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"term": {
"language": "mandarin" // Returns a doc
}
},
{
"term": {
"language": "Italian" // Does NOT return a doc, but will if lowercased
}
}
]
}
}
}
}
}

我有一个 languages 类型,我使用了小写:

"analyzer": {
"lower_keyword": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}

和相应的映射:

"mappings": {
"languages": {
"_id": {
"path": "languageID"
},
"properties": {
"languageID": {
"type": "integer"
},
"language": {
"type": "string",
"analyzer": "lower_keyword"
},
"native": {
"type": "string",
"analyzer": "keyword"
},
"meta": {
"type": "nested"
},
"language_suggest": {
"type": "completion"
}
}
}
}

最佳答案

问题是您有一个在索引期间分析过的字段以将其小写,但您正在为未分析的查询使用术语过滤器:

Term Filter

Filters documents that have fields that contain a term (not analyzed). Similar to term query, except that it acts as a filter.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html

我会尝试使用查询过滤器:

Query Filter

Wraps any query to be used as a filter. Can be placed within queries that accept a filter.

示例:

{
"constantScore" : {
"filter" : {
"query" : {
"query_string" : {
"query" : "this AND that OR thus"
}
}
}
} }

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html#query-dsl-query-filter

关于search - Elasticsearch 小写过滤搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24811243/

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