特殊查询(percolator)
- 创建
curl -X PUT "localhost:9200/my-index" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
}
'
- 注册一个查询到 percolator
curl -X PUT "localhost:9200/my-index/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
}
'
- 匹配使用
curl -X GET "localhost:9200/my-index/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field" : "query",
"document" : {
"message" : "A new bonsai tree in the office"
}
}
}
}
'
# 结果
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.5753642,
"hits" : [
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.5753642,
"_source" : {
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
},
"fields" : {
"_percolator_document_slot" : [
0
]
}
}
]
}
}
注:查询的字段必须包含在创建的映射中。
参考: