Skip to content

Instantly share code, notes, and snippets.

@nuria
Created March 20, 2023 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuria/380f13622418d31192818cc4ebbd06ba to your computer and use it in GitHub Desktop.
Save nuria/380f13622418d31192818cc4ebbd06ba to your computer and use it in GitHub Desktop.
Percolator OpenSearch Example
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