首页 > 代码库 > PHP通过API搜索elasticsearch只获得10条数据

PHP通过API搜索elasticsearch只获得10条数据

PHP通过API对ES进行搜索后发现只能获取10条数据,搜索语句如下:

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "level:\"警告\" AND source_name:\"ASP.NET\" ",
          "analyze_wildcard": true
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gte": 1494309300,
                  "lte": 1494489299,
                  "format": "epoch_second"
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
}
}

其余ES如果没有指定SIZE的话,默认是10条

http://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.search

但是size也不能超过10000,否则也会报错。


修改搜索语句如下:

{
  "size": 10000,
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "level:\"警告\" AND source_name:\"ASP.NET\" ",
          "analyze_wildcard": true
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gte": 1494309300,
                  "lte": 1494489299,
                  "format": "epoch_second"
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
}
}

即可

本文出自 “枫林晚” 博客,请务必保留此出处http://fengwan.blog.51cto.com/508652/1924597

PHP通过API搜索elasticsearch只获得10条数据