【问题标题】:Lucene Query String Elasticsearch "less than or equal to"[URI Search]Lucene查询字符串Elasticsearch“小于等于”【URI搜索】
【发布时间】:2014-05-15 09:27:19
【问题描述】:

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

fieldname:[* TO 100] 

fieldname:["*" TO "100"]

我尝试过其他格式,但都没有奏效。有人可以帮我吗?

【问题讨论】:

  • 我已经更新了我的答案..
  • 如果您对答案不满意,请再次询问。不要放弃问题。接受答案并帮助他人..
  • 刚刚尝试了@John Petrone 的答案,它奏效了。字段名:

标签: elasticsearch query-string


【解决方案1】:

您需要结合使用查询字符串语法 (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) 范围和 URI 搜索 (https://www.elastic.co/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.

URI 搜索

搜索 URI 搜索请求正文搜索 搜索分片 API 搜索 模板构面聚合建议器上下文建议器多搜索 API Count API Validate API Explain API Percolator 更像这个 API 基准

搜索请求可以纯粹使用 URI 执行,方法是提供 请求参数。执行时并非所有搜索选项都公开 使用此模式进行搜索,但它对于快速“卷曲测试”很方便。 这是一个例子:

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

【讨论】:

    【解决方案2】:

    我想你想查询小于等于 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]"
    

    希望它有帮助..!

    【讨论】:

    • 我认为这不是 Lucene 查询字符串。我使用 Elasticsearch PHP 客户端 API,我不想使用 JSON 或数组格式作为参数来查询数据,而是想使用 Lucene 查询字符串。
    • 现在是 1.0。希望你能帮帮我。
    • 你应该以你想要的格式提及你的查询。给我一些时间我会回复你
    • 例如:字段名:
    猜你喜欢
    • 2017-03-28
    • 1970-01-01
    • 2020-10-09
    • 2018-09-15
    • 2015-02-05
    • 2018-06-29
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    相关资源
    最近更新 更多