Skip to content

Instantly share code, notes, and snippets.

@psylone
Last active October 29, 2018 14:50
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 psylone/b9c2e2297f7fde9621cb5dffecb93bca to your computer and use it in GitHub Desktop.
Save psylone/b9c2e2297f7fde9621cb5dffecb93bca to your computer and use it in GitHub Desktop.
# Elasticsearch version: 6.3.1
# Create single index for documents and percolate queries
curl -X PUT "localhost:9200/books" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"author": {
"type": "text"
},
"title": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
}
'
# Index document
curl -XPUT "localhost:9200/books/_doc/1" -H 'Content-Type: application/json' -d'
{
"author": "Zachary Tong",
"title": "Elasticsearch: The Definitive Guide"
}'
# Index percolate query
curl -X PUT "localhost:9200/books/_doc/query_1" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"title" : "guide"
}
}
}
'
# Percolate queries with the document
curl -X GET "localhost:9200/books/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field": "query",
"document": {
"author": "Zachary Tong",
"title": "Elasticsearch: The Definitive Guide"
}
}
}
}
'
# Percolate queries with the stored document
curl -X GET "localhost:9200/books/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field": "query",
"index": "books",
"type": "_doc",
"id": 1
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment