Range facets and filters

Mapping

{
  "id": { "type": "keyword" },
  "title": { "type": "text" },
  "price": { "type": "float" },
  "rating": { "type": "integer" }
}

Documents

{
  "documents": [
    { "id": "1", "title": "Laptop HP 1", "price": 128.99, "rating": 5 },
    { "id": "2", "title": "Laptop HP 2", "price": 520.0, "rating": 4 },
    { "id": "3", "title": "Laptop HP 3", "price": 230.99, "rating": 3 },
    { "id": "4", "title": "Laptop HP 4", "price": 768.64, "rating": 5 },
    { "id": "5", "title": "Laptop Lenovo 1", "price": 800.2, "rating": 4 },
    { "id": "6", "title": "Laptop Lenovo 2", "price": 999.999, "rating": 2 },
    { "id": "7", "title": "Laptop Lenovo 3", "price": 1024.29, "rating": 5 },
    { "id": "8", "title": "Laptop Lenovo 4", "price": 620.6, "rating": 1 }
  ]
}

Query Configuration

{
  "description": "Computer query",
  "configuration": {
    "queryFields": {
      "title": 5
    },
    "match": "all",
    "selectFields": ["id"],
    "facets": [
      {
        "type": "range",
        "key": "price",
        "label": "Price",
        "ranges": [
          {
            "to": 500
          },
          {
            "from": 500,
            "to": 1000
          },
          {
            "from": 1000
          }
        ]
      },
      {
        "type": "range",
        "key": "rating",
        "label": "Rating",
        "ranges": {
          "min": 1,
          "max": 6,
          "step": 1
        }
      }
    ]
  },
  "debugMode": true
}

Public query

Range facets

Request:

{
  "searchText": "laptop"
}

Response:

{
  "searchText": "laptop",
  "total": 8,
  "items": [
    /*...*/
  ],
  "facets": [
    {
      "key": "price",
      "label": "Price",
      "items": [
        {
          "title": "*-500.0",
          "count": 2,
          "to": 500
        },
        {
          "title": "500.0-1000.0",
          "count": 5,
          "from": 500,
          "to": 1000
        },
        {
          "title": "1000.0-*",
          "count": 1,
          "from": 1000
        }
      ],
      "type": "range"
    },
    {
      "key": "rating",
      "label": "Rating",
      "items": [
        {
          "title": "1.0-2.0",
          "count": 1,
          "from": 1,
          "to": 2
        },
        {
          "title": "2.0-3.0",
          "count": 1,
          "from": 2,
          "to": 3
        },
        {
          "title": "3.0-4.0",
          "count": 1,
          "from": 3,
          "to": 4
        },
        {
          "title": "4.0-5.0",
          "count": 2,
          "from": 4,
          "to": 5
        },
        {
          "title": "5.0-6.0",
          "count": 3,
          "from": 5,
          "to": 6
        }
      ],
      "type": "range"
    }
  ],
  "filters": {},
  "metadata": {}
}

Range - filters

Request:

{
  "searchText": "laptop",
  "filters": {
    "price": { "gt": 150, "lte": 800.2 }
  }
}

Response:

{
  "searchText": "laptop",
  "total": 5,
  "items": [
    /*...*/
  ],
  "facets": [
    {
      "key": "price",
      "label": "Price",
      "items": [
        {
          "title": "*-500.0",
          "count": 2,
          "to": 500
        },
        {
          "title": "500.0-1000.0",
          "count": 5,
          "from": 500,
          "to": 1000
        },
        {
          "title": "1000.0-*",
          "count": 1,
          "from": 1000
        }
      ],
      "type": "range"
    },
    {
      "key": "rating",
      "label": "Rating",
      "items": [
        {
          "title": "1.0-2.0",
          "count": 1,
          "from": 1,
          "to": 2
        },
        {
          "title": "2.0-3.0",
          "count": 0,
          "from": 2,
          "to": 3
        },
        {
          "title": "3.0-4.0",
          "count": 1,
          "from": 3,
          "to": 4
        },
        {
          "title": "4.0-5.0",
          "count": 2,
          "from": 4,
          "to": 5
        },
        {
          "title": "5.0-6.0",
          "count": 1,
          "from": 5,
          "to": 6
        }
      ],
      "type": "range"
    }
  ],
  "filters": {
    "price": {
      "gt": 150,
      "lte": 800.2
    }
  },
  "metadata": {}
}

Range - multiple filters

Request:

{
  "searchText": "laptop",
  "filters": {
    "price": { "gt": 150, "lte": 800.2 },
    "rating": { "gte": 5 }
  }
}

Response:

{
  "searchText": "laptop",
  "total": 1,
  "items": [
    {
      "id": "4"
    }
  ],
  "facets": [
    {
      "key": "price",
      "label": "Price",
      "items": [
        {
          "title": "*-500.0",
          "count": 1,
          "to": 500
        },
        {
          "title": "500.0-1000.0",
          "count": 1,
          "from": 500,
          "to": 1000
        },
        {
          "title": "1000.0-*",
          "count": 1,
          "from": 1000
        }
      ],
      "type": "range"
    },
    {
      "key": "rating",
      "label": "Rating",
      "items": [
        {
          "title": "1.0-2.0",
          "count": 1,
          "from": 1,
          "to": 2
        },
        {
          "title": "2.0-3.0",
          "count": 0,
          "from": 2,
          "to": 3
        },
        {
          "title": "3.0-4.0",
          "count": 1,
          "from": 3,
          "to": 4
        },
        {
          "title": "4.0-5.0",
          "count": 2,
          "from": 4,
          "to": 5
        },
        {
          "title": "5.0-6.0",
          "count": 1,
          "from": 5,
          "to": 6
        }
      ],
      "type": "range"
    }
  ],
  "filters": {
    "price": {
      "gt": 150,
      "lte": 800.2
    },
    "rating": {
      "gte": 5
    }
  },
  "metadata": {}
}