加载中

使用 Elasticsearch Query DSL 进行过滤

您可以使用标准的 Elasticsearch Query DSL,通过在 `filter` 参数中指定查询来过滤 SQL 将要运行的结果。

				POST /_sql?format=txt
					{
  "query": "SELECT * FROM library ORDER BY page_count DESC",
  "filter": {
    "range": {
      "page_count": {
        "gte" : 100,
        "lte" : 200
      }
    }
  },
  "fetch_size": 5
}
		

返回

    author     |                name                |  page_count   | release_date
---------------+------------------------------------+---------------+------------------------
Douglas Adams  |The Hitchhiker's Guide to the Galaxy|180            |1979-10-12T00:00:00.000Z
		
提示

标准 Query DSL 过滤的一个有用但不太明显的用法是根据特定的 路由键 来搜索文档。由于 Elasticsearch SQL 不支持 routing 参数,因此可以改为指定 针对 _routing 字段的 terms 过滤器

				POST /_sql?format=txt
					{
  "query": "SELECT * FROM library",
  "filter": {
    "terms": {
      "_routing": ["abc"]
    }
  }
}
		
© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.