Last active
October 29, 2018 14:50
-
-
Save psylone/b9c2e2297f7fde9621cb5dffecb93bca to your computer and use it in GitHub Desktop.
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
# 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