Lucene查询字符串Elasticsearch"小于或等于"[URI搜索]

O C*_*nor 30 query-string elasticsearch

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

fieldname:[* TO 100] 
Run Code Online (Sandbox Code Playgroud)

要么

fieldname:["*" TO "100"]
Run Code Online (Sandbox Code Playgroud)

我尝试过其他格式,但没有一种有效.有人能帮我吗?

Joh*_*one 48

您将需要使用查询字符串语法(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]和带括号{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.
Run Code Online (Sandbox Code Playgroud)

URI搜索

搜索URI搜索请求正文搜索搜索Shards API搜索模板构面聚合建议者上下文建议者多搜索API计数API验证API解释API过滤器更像此API基准

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

$ curl -XGET
'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'
Run Code Online (Sandbox Code Playgroud)


Bla*_*POP 4

我想你想查询小于等于100的文档。

 curl -XPOST "http://hostname:9200/index/try/_search" -d'
{
 "query": {
    "range": {
      "FieldName": {
         "lte" : 100
      }
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

PHP API 客户端

array(
'query' => array(
    'range' => array(
        'FieldName' => array(
            array("lte" => 100)
        )
    )
  )
);
Run Code Online (Sandbox Code Playgroud)

如需更多查询..请参阅

您要求的查询格式..!

curl -XPOST "http://hostname:9200/index/type/_search?q=FieldName:[* to 100]"
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你..!

  • 我认为这不是 Lucene 查询字符串。我使用 Elasticsearch PHP 客户端 API,并且不想使用 JSON 或数组格式作为参数来查询数据,而是想使用 Lucene 查询字符串。 (4认同)