如何使用elasticsearch-dsl-py在整数字段上创建“介于”条件过滤器?

时间:2020-08-19 06:29:13

标签: python python-3.x elasticsearch dsl

下面的查询是我想使用elasticsearch-dsl-py构造的,但是我不知道该怎么做。

GET /myindex/_search/
{
  "query": {
    "range": {
      "int_field": {
        "gte": "2455",
        "lte": "2455"
      }
    }
  }
}

我只想以SQL格式执行以下查询

select * from my_index where int_field >= 777 or int_field <= 779

使用elasticsearch-dsl-py,它与我所能接近的程度差不多,但是并不相同。

class MyIndex(Document):

    int_field = Integer()
    
    

MyIndex.search().filter('range', int_field={"gte": 2454,"lte": 2456})

以上代码给出了以下错误

{“错误”:{ “根本原因”: [ { “ type”:“ query_shard_exception”, “ reason”:“无法创建查询:{\ n” range“:{\ n” int_field“:{\ n” from“:2454,\ n” to“:2456,\ n
“ include_lower”:false,\ n“ include_upper”:true,\ n
“ boost”:1.0 \ n} \ n} \ n}“, “ index_uuid”:“ HRdIrs3LRnqO_5rbSjZi7A”, “ index”:“ myindex” } ], “ type”:“ search_phase_execution_exception”, “ reason”:“所有分片均失败”, “ phase”:“查询”, “分组”:是的, “ failed_shards”:[ { “碎片”:0, “ index”:“ myindex”, “ node”:“ t-bkDruUSh61vUvKAlX2fw”, “原因”:{ “ type”:“ query_shard_exception”, “ reason”:“无法创建查询:{\ n” range“:{\ n” int_field“:{\ n” from“:2454,\ n” to“:2456,\ n
“ include_lower”:false,\ n“ include_upper”:true,\ n
“ boost”:1.0 \ n} \ n} \ n}“, “ index_uuid”:“ HRdIrs3LRnqO_5rbSjZi7A”, “ index”:“ myindex”, “ caused_by”:{ “ type”:“ illegal_argument_exception”, “ reason”:“由于未索引字段[int_field],因此无法搜索。” } } } ]},“状态”:400}

0 个答案:

没有答案