弹性搜索小写滤镜搜索 [英] Elasticsearch lowercase filter search
问题描述
我正在尝试搜索我的数据库,并且可以使用大小写过滤条款,但是我在查询
的应用分析器时注意到,我可以'了解如何在筛选的搜索上应用小写分析器。这是查询:
{
查询:{
过滤:{
filter:{
bool:{
should:[
{
term:{
language:mandarin /返回一个文档
}
},
{
term:{
language:Italian//不返回文档,如果下调
}
}
]
}
}
}
}
}
我有一个类型语言
,我已经使用下列方式:
分析器:{
lower_keyword:{
type:custom,
tokenizer:关键字,
过滤器:小写
}
}
相应的映射:
映射:{
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
}
}
}
}
问题是您有一个您在索引小写它,但您正在对未进行分析的查询使用术语过滤器:
术语过滤器
过滤包含术语(未分析)字段的文档。
类似于术语查询,除了它作为过滤器。
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current /query-dsl-term-filter.html
我会尝试使用查询过滤器:
查询过滤器
包装任何用作过滤器的查询。可以放在接受过滤器的查询
中。
示例:
查询:{
query_string:{
查询:{
查询:这AND AND OR OR
}
}
}
}}
I'm trying to search my database and be able to use upper/lower case filter terms but I've noticed while query
's apply analyzers, I can't figure out how to apply a lowercase analyzer on a filtered search. Here's the query:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"term": {
"language": "mandarin" // Returns a doc
}
},
{
"term": {
"language": "Italian" // Does NOT return a doc, but will if lowercased
}
}
]
}
}
}
}
}
I have a type languages
that I have lowercased using:
"analyzer": {
"lower_keyword": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
and a corresponding mapping:
"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"
}
}
}
}
The problem is that you have a field that you have analyzed during index to lowercase it, but you are using a term filter for the query which is not analyzed:
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
I'd try using a query filter instead:
Query Filter
Wraps any query to be used as a filter. Can be placed within queries that accept a filter.
Example:
{
"constantScore" : {
"filter" : {
"query" : {
"query_string" : {
"query" : "this AND that OR thus"
}
}
}
} }
这篇关于弹性搜索小写滤镜搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!