Lucene Query String Elasticsearch“小于或等于”[URI搜索] [英] Lucene Query String Elasticsearch "less than or equal to"[URI Search]

查看:823
本文介绍了Lucene Query String Elasticsearch“小于或等于”[URI搜索]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这么多网站上,他们教导如何使用范围查询来查询Elasticsearch中的数据。我想使用Lucene样式查询字符串从Elasticsearch查询小于或等于某个数字的数据。

  fieldname:[* TO 100] 

 字段名称:[*TO100] 
我已经尝试过其他格式,但没有一个工作。有人可以帮助我吗?

解决方案

你将要使用查询字符串语法(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl -query-string-query.html )范围与URI搜索结合( http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-uri-request.html


范围



可以为日期,数字或字符串字段指定范围。包含
范围用方括号[最小到最大]和排他
范围指定,大括号{最小最大}。

  2012年的所有日子:

日期:[2012/01/01 TO 2012/12/31]

数字1..5

计数:[1到5]

除了alpha和omega之外的alpha和omega之间的标签:

标签:{alpha to omega}

从10开始的数字

计数:[10 TO *]

2012年以前的日期

日期:{* TO 2012/01 / 01}

可以组合卷曲和方括号:

从1到但不包括5

的数字计数:[1 .. 5}

单边无界的范围可以使用以下语法:

age:> 10
age:> = 10
age: < 10
age:< = 10

注意

要将上限和下限与简化语法组合,您需要加入两个子句AND运算符:

age:(> = 10 AND< 20)
age:(+> = 10 +< 20)

查询字符串中范围的解析可能很复杂,容易出错。使用显式范围过滤器可靠性更高。

URI搜索



搜索URI搜索请求身体搜索搜索碎片API搜索
模板facets聚合Suggesters上下文Suggester多搜索
API Count API验证API说明API Percolator更像此API
基准



可以通过提供
请求参数来纯粹使用URI执行搜索请求。当使用此模式执行
搜索时,并不是所有的搜索选项都会公开,但是它可以方便快速的卷曲测试。
这是一个例子:




  $ curl -XGET 
' http:// localhost:9200 / twitter / tweet / _search?q = user:kimchy'


On so many websites they teach how to query data from Elasticsearch using range query. I would like to query data that is less than or equal to a certain number from Elasticsearch using Lucene Style Query String like this.

fieldname:[* TO 100] 

or

fieldname:["*" TO "100"]

I have tried in other formats but none of those worked. Can someone help me?

解决方案

You will want to use Query String Syntax (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) ranges combined with the URI Search (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-uri-request.html)

Ranges

Ranges can be specified for date, numeric or string fields. Inclusive ranges are specified with square brackets [min TO max] and exclusive ranges with curly brackets {min TO max}.

    All days in 2012:

    date:[2012/01/01 TO 2012/12/31]

    Numbers 1..5

    count:[1 TO 5]

    Tags between alpha and omega, excluding alpha and omega:

    tag:{alpha TO omega}

    Numbers from 10 upwards

    count:[10 TO *]

    Dates before 2012

    date:{* TO 2012/01/01}

Curly and square brackets can be combined:

    Numbers from 1 up to but not including 5

    count:[1..5}

Ranges with one side unbounded can use the following syntax:

age:>10
age:>=10
age:<10
age:<=10

Note

To combine an upper and lower bound with the simplified syntax, you would need to join two clauses with an AND operator:

age:(>=10 AND < 20)
age:(+>=10 +<20)

The parsing of ranges in query strings can be complex and error prone. It is much more reliable to use an explicit range filter.

URI Search

Search URI Search Request Body Search Search Shards API Search Template Facets Aggregations Suggesters Context Suggester Multi Search API Count API Validate API Explain API Percolator More Like This API Benchmark

A search request can be executed purely using a URI by providing request parameters. Not all search options are exposed when executing a search using this mode, but it can be handy for quick "curl tests". Here is an example:

$ curl -XGET
'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'

这篇关于Lucene Query String Elasticsearch“小于或等于”[URI搜索]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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