duandai2178 2016-10-08 21:16
浏览 37
已采纳

在弹性搜索中搜索“少于/超过价值”

I have 3 field in my document:

  • id
  • title
  • txt

I have inserted several records into the index(articles) with the following code:

$es = Elasticsearch\ClientBuilder::create()->build();

$params = [
    'index'=>'articles',
    'type'  => 'article'
];

for ($i=1; $i<50000; $i++) {
    $params['body'] = [ 
       'id' => $i, 
       'title'=>'some title '.$i, 
       'txt'=>'some text '.$i
    ];
    $response = $es->index($params);
}

Now I want to retrieve records where id > 20000. How can perform filters like this, in Elasticsearch?

  • 写回答

1条回答 默认 最新

  • douliang4858 2016-10-09 07:10
    关注

    First, you need to make sure that your id field is saved as long, you can do this by executing a GET request to <ES_HOST>:9200/articles/article/_mapping,

    Then you can run this query to get the relevant ids:

    {
        "query": {
            "bool": {
                "filter": {
                    "range": {
                        "id": {
                            "gt": 20000
                        }
                    }
                }
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!