Created
March 20, 2023 23:28
-
-
Save nuria/380f13622418d31192818cc4ebbd06ba to your computer and use it in GitHub Desktop.
Percolator OpenSearch Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE /percolator-queries | |
PUT percolator-queries | |
{ | |
"mappings": { | |
"properties": { | |
"search": { | |
"properties": { | |
"query": { | |
"type": "percolator" | |
} | |
} | |
}, | |
"price": { | |
"type": "float" | |
}, | |
"item": { | |
"type": "text" | |
} | |
} | |
} | |
} | |
PUT percolator-queries/_doc/car_alert_less_than_400 | |
{ | |
"search": { | |
"query": { | |
"bool": { | |
"filter": [ | |
{ | |
"match": { | |
"item": { | |
"query": "car" | |
} | |
} | |
}, | |
{ | |
"range": { | |
"price": { | |
"lte": 400.00 | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
PUT catalog | |
{ | |
"mappings": { | |
"properties": { | |
"item" : { "type" : "keyword" }, | |
"price" : { "type" : "long" } | |
} | |
} | |
} | |
PUT catalog/_bulk?refresh | |
{ "index" : { "_id": "1" } } | |
{"item" : "Big car", "price": 60000 } | |
{ "index" : { "_id": "2" } } | |
{ "item" : "potato", "price": 40000 } | |
{ "index" : { "_id": "3"} } | |
{ "item" : "big table", "price": 50 } | |
{ "index" : { "_id": "4"} } | |
{ "item" : "small car", "price": 50 } | |
{ "index" : { "_id": "5"} } | |
{ "item" : "car", "price": 50 } | |
GET /catalog/_search | |
GET percolator-queries/_search | |
{ | |
"query" : { | |
"bool" : { | |
"filter" : | |
{ | |
"percolate" : { | |
"field" : "search.query", | |
"document" : { | |
"item" : "car", | |
"price": 399.99 | |
} | |
} | |
} | |
} | |
} | |
} | |
GET percolator-queries/_search | |
{ | |
"query" : { | |
"bool" : { | |
"filter" : | |
{ | |
"percolate" : { | |
"field" : "search.query", | |
"index" : "catalog", | |
"id": "5" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment