上QQ阅读APP看书,第一时间看更新
How to do it...
For mapping a percolator field, use the followings steps:
- We want to create a Percolator that matches some text in a body field. We will define mapping in a similar way:
PUT test-percolator
{
"mappings": {
"properties": {
"query": {
"type": "percolator"
},
"body": {
"type": "text"
}
}
}
}
- Now, we can store a document with a query percolator inside it, as follows:
PUT test-percolator/_doc/1?refresh
{
"query": {
"match": {
"body": "quick brown fox"
}
}
}
- We can now execute a search on it, as shown in the following code:
GET test-percolator/_search
{
"query": {
"percolate": {
"field": "query",
"document": {
"body": "fox jumps over the lazy dog"
}
}
}
}
- The result will return in the hits of the stored document, as follows:
{
... truncated...
"hits" : [
{
"_index" : "test-percolator",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"query" : {
"match" : {
"body" : "quick brown fox"
}
}
},
"fields" : {
"_percolator_document_slot" : [0]
}
}
]
}
}