弹性搜索小写滤镜搜索

编程入门 行业动态 更新时间:2024-10-26 02:26:35
本文介绍了弹性搜索小写滤镜搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试搜索我的数据库,并且可以使用大小写过滤条款,但是我在查询的应用分析器时注意到,我可以'了解如何在筛选的搜索上应用小写分析器。这是查询:

{查询:{过滤:{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} } } }

解决方案

问题是您有一个您在索引小写它,但您正在对未进行分析的查询使用术语过滤器:

术语过滤器

过滤包含术语(未分析)字段的文档。 类似于术语查询,除了它作为过滤器。

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

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

查询过滤器

包装任何用作过滤器的查询。可以放在接受过滤器的查询中。

示例:

查询:{query_string:{查询:{ 查询:这AND AND OR OR} } } }}

www.elasticsearch/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html#query-dsl-query-过滤器

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.

www.elasticsearch/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" } } } } }

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

更多推荐

弹性搜索小写滤镜搜索

本文发布于:2023-11-30 00:33:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:滤镜   弹性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!