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

Implementing a prize range filter

Now, let's move on and see how to implement a prize range filter as seen in some e-commerce websites. Consider the following screenshot of an e-commerce site:

In the preceding screenshot, you can see a price range filter on the left-hand side tab. By clicking on or specifying the price ranges, the products that fall within that range would be displayed. This is nothing but a numeric range filter.

The implementation of a numeric range filter is almost similar to the date range filter in Elasticsearch. The following code snippet shows how to implement a numeric range filter. Here is the sample; assume that you have an age field that is numeric in nature:

{
    "filtered" : {
        "filter" : {
            "range" : {
                "age" : {
                    "gte": 10,
                    "lte": 20
                }
            }
        }
    }
}

After reading the implementation of filters, which is to be followed, you would understand the snippet completely. For time being, we have just showed you how to implement a filter in a numeric field in Elasticsearch.

The same parameters that are shown in the previous table are applied here as well.

主站蜘蛛池模板: 甘南县| 新蔡县| 喀什市| 修武县| 贞丰县| 香格里拉县| 临西县| 东港市| 平凉市| 汕头市| 齐河县| 大余县| 家居| 屏山县| 资中县| 乐平市| 鄂托克前旗| 台中县| 香港| 巩义市| 林西县| 临桂县| 房山区| 民县| 凯里市| 叶城县| 平泉县| 武宣县| 甘德县| 东平县| 铅山县| 丰原市| 韩城市| 正定县| 疏附县| 稷山县| 沽源县| 浮山县| 富川| 阿拉尔市| 葵青区|