- Elasticsearch Blueprints
- Vineeth Mohan
- 202字
- 2021-07-16 13:39:33
Filter your results based on a date range
With a fair idea in mind of when to use your filter and when to opt for a query, let's think of some scenarios and see how Elasticsearch enables filtering at its best. Filtering by a date range, prize, or department often pops up in use cases in an e-commerce view. Look at the left-hand side of the following figure:

Checking for new arrivals or selecting an old classic song from a library may need a date-range-based filtering mechanism. Elasticsearch provides inbuilt facilities to do filtering by providing a date range filter. A term filter does the same thing for strings, which can be anything for example, a department or category. A numeric filter filters numerals and can be used for prizes and so on.
This snippet shows how you can implement a date-range-based filtering in Elasticsearch:
{ "query" : { "filtered" : { "query" : { "text" : { "content" : "any keywords to match" } }, "filter" : { "numeric_range" : { "date" : { "lt" : "2011-02-01", "gte" : "2011-01-01" } } } }
These are the parameters taken in a range filter that you may use to specify range offsets:
- DevOps with Kubernetes
- 劍指Offer(專項突破版):數據結構與算法名企面試題精講
- Magento 2 Development Cookbook
- The DevOps 2.4 Toolkit
- Python Data Analysis Cookbook
- Node.js全程實例
- Kotlin編程實戰(zhàn):創(chuàng)建優(yōu)雅、富于表現力和高性能的JVM與Android應用程序
- 單片機C語言程序設計實訓100例
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- 軟件項目管理實用教程
- .NET Standard 2.0 Cookbook
- Unity Android Game Development by Example Beginner's Guide
- Learning D
- Deep Learning for Natural Language Processing
- JavaScript Concurrency