在如此多的网站上,他们教授如何使用范围查询从Elasticsearch查询数据。我想使用像这样的Lucene Style Query String从Elasticsearch查询小于或等于某个数字的数据。
fieldname:[* TO 100]
或
fieldname:["*" TO "100"]
我尝试过其他格式,但没有一种有效。有人能帮助我吗?
答案 0 :(得分:39)
您将需要使用查询字符串语法(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)
结合使用范围
可以为日期,数字或字符串字段指定范围。包括的 范围用方括号[min TO max]和exclusive指定 带括号的范围{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搜索
搜索URI搜索请求正文搜索搜索Shards API搜索 模板构面聚合建议者上下文建议器多搜索 API计数API验证API解释API过滤器更像此API 基准
搜索请求可以通过提供纯粹使用URI执行 请求参数。执行时并非所有搜索选项都会公开 使用此模式进行搜索,但它可以方便地进行快速&#34;卷曲测试&#34;。 这是一个例子:
$ curl -XGET
'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'
答案 1 :(得分:1)
我认为您想要查询小于等于100的文档。
curl -XPOST "http://hostname:9200/index/try/_search" -d'
{
"query": {
"range": {
"FieldName": {
"lte" : 100
}
}
}
}'
PHP API客户端
array(
'query' => array(
'range' => array(
'FieldName' => array(
array("lte" => 100)
)
)
)
);
了解更多查询.. refer
您要求的查询格式..!
curl -XPOST "http://hostname:9200/index/type/_search?q=FieldName:[* to 100]"
它有帮助......!