原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-rest-filtering.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/sql-rest-filtering.html
本地英文版地址: ../en/sql-rest-filtering.html
重要: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 当前版本文档。
Filtering using Elasticsearch query DSLedit
One can filter the results that SQL will run on using a standard Elasticsearch query DSL by specifying the query in the filter parameter.
POST /_sql?format=txt { "query": "SELECT * FROM library ORDER BY page_count DESC", "filter": { "range": { "page_count": { "gte" : 100, "lte" : 200 } } }, "fetch_size": 5 }
Which returns:
author | name | page_count | release_date ---------------+------------------------------------+---------------+------------------------ Douglas Adams |The Hitchhiker's Guide to the Galaxy|180 |1979-10-12T00:00:00.000Z
A useful and less obvious usage for standard query DSL filtering is to search documents by a specific routing key.
Because Elasticsearch SQL does not support a routing
parameter, one can specify a terms
filter for the _routing
field instead:
POST /_sql?format=txt { "query": "SELECT * FROM library", "filter": { "terms": { "_routing": ["abc"] } } }