Elasticsearch-从过滤器开始? [英] Elasticsearch - startswith filter?

查看:73
本文介绍了Elasticsearch-从过滤器开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Elasticsearch中获得一个简单的startswith功能.例如,我希望查询"char"匹配"charlotte",但我不希望它匹配"dacharlotte".使用edgeNgram过滤器可以得到后一个结果.我只希望它匹配以查询词开头的结果,而不只是将它们包含在其中.

I am trying to get a simple startswith functionality in Elasticsearch. For example, I want the query "char" to match "charlotte", but I don't want it to match "dacharlotte". Using an edgeNgram filter gave me the latter result. I only want it to match results that START with the query terms, not just have them in them.

推荐答案

最简单的方法是使用前缀查询:

The simplest way to do what you want would be to use the prefix query:

{
    "query": {
         "prefix":{ "name" : "char" }
     }
}

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

这篇关于Elasticsearch-从过滤器开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆