datadabllp

full-text search, boolean logic, and range filters

Jul 19th, 2024
1,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.79 KB | None | 0 0
  1. PUT /products
  2. {
  3.   "mappings": {
  4.     "properties": {
  5.       "name": { "type": "text" },
  6.       "description": { "type": "text" },
  7.       "price": { "type": "float" },
  8.       "category": { "type": "keyword" },
  9.       "in_stock": { "type": "boolean" }
  10.     }
  11.   }
  12. }
  13.  
  14. POST /products/_doc
  15. {
  16.   "name": "Ergonomic Office Chair",
  17.   "description": "Comfortable chair with lumbar support",
  18.   "price": 199.99,
  19.   "category": "Furniture",
  20.   "in_stock": true
  21. }
  22.  
  23. GET /products/_search
  24. {
  25.   "query": {
  26.     "bool": {
  27.       "must": [
  28.         { "match": { "name": "chair" } },
  29.         { "term": { "in_stock": true } }
  30.       ],
  31.       "filter": {
  32.         "range": { "price": { "lte": 200 } }
  33.       }
  34.     }
  35.   },
  36.   "aggs": {
  37.     "categories": {
  38.       "terms": { "field": "category" }
  39.     }
  40.   }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment