Percolator 字段类型
1.0 版引入
一个 percolator
字段类型指定将此字段视为一个查询。任何 JSON 对象字段都可以标记为 percolator
字段。通常,文档会被索引,然后对其运行搜索。当您使用 percolator
字段时,您存储一个搜索,然后 percolate
查询会将文档与该搜索进行匹配。有关详细示例,请参阅Percolate 查询。
示例
一位客户正在寻找价格为 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
}
}
}
]
}
}
}
}
查询中引用的字段必须已存在于映射中。
运行 percolate 查询以搜索匹配的文档
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
]
}
}
]
}
}