官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 旌德县| 茂名市| 西平县| 团风县| 盐亭县| 云阳县| 安溪县| 台东市| 弥勒县| 襄樊市| 海伦市| 喀什市| 南乐县| 余庆县| 双城市| 宜良县| 兴城市| 旺苍县| 遂宁市| 永寿县| 伊金霍洛旗| 和硕县| 密云县| 鄢陵县| 灵璧县| 石阡县| 宜州市| 安龙县| 额济纳旗| 吉安县| 民权县| 绥阳县| 卓资县| 木兰县| 九龙城区| 宝清县| 麦盖提县| 新巴尔虎右旗| 荥阳市| 江山市| 新民市|