Percolator字段类型
一个渗透器字段类型指定将此字段视为查询。任何JSON对象字段都可以标记为渗透器字段。通常,文档被索引并对它们进行搜索。当您使用渗透器字段时,您存储一个搜索,然后渗透查询将文档与该搜索匹配。
示例
客户正在寻找价格在400美元或以下的桌子,并希望为此搜索创建一个警报。
创建一个将每个查询字段分配给一个percolator字段类型的映射:
PUT testindex1
{
"mappings": {
"properties": {
"search": {
"properties": {
"query": {
"type": "percolator"
}
}
},
"price": {
"type": "float"
},
"item": {
"type": "text"
}
}
}
}
索引查询:
PUT testindex1/_doc/1
{
"search": {
"query": {
"bool": {
"filter": [
{
"match": {
"item": {
"query": "table"
}
}
},
{
"range": {
"price": {
"lte": 400.00
}
}
}
]
}
}
}
}
查询中引用的字段必须已在映射中存在。
运行一个过滤查询以搜索匹配的文档:
GET testindex1/_search
{
"query" : {
"bool" : {
"filter" :
{
"percolate" : {
"field" : "search.query",
"document" : {
"item" : "Mahogany table",
"price": 399.99
}
}
}
}
}
}
响应包含原始索引查询:
{
"took" : 30,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "testindex1",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.0,
"_source" : {
"search" : {
"query" : {
"bool" : {
"filter" : [
{
"match" : {
"item" : {
"query" : "table"
}
}
},
{
"range" : {
"price" : {
"lte" : 400.0
}
}
}
]
}
}
}
},
"fields" : {
"_percolator_document_slot" : [
0
]
}
}
]
}
}