我正在尝试渗透一些文本并添加匹配的超链接。但在添加超链接之前,我无法想象如何突出显示多个单词。以下是该场景的快乐路径:
- 像这样添加映射:
醇>
curl -X PUT "localhost:9200/my-index" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
}
'
- 在过滤器中注册查询
醇>
curl -X PUT "localhost:9200/my-index/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"message" : "the bonsai three in a jungle"
}
}
}
'
- 使用我的percolate查询突出显示的新文档
醇>
curl -X GET "localhost:9200/my-index/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field": "query",
"document" : {
"title" : "A new bonsai tree in the office and jungle"
}
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
'
输出:
{
"took":10,
"timed_out":false,
"_shards":{
"total":#,
"successful":#,
"skipped":0,
"failed":0
},
"hits":{
"total":#,
"max_score":1.7260926,
"hits":[
{
"_index":"my-index",
"_type":"_doc",
"_id":"1",
"_score":1.7260926,
"_source":{
"query":{
"match":{
"title":"the bonsai tree in a jungle"
}
}
},
"fields":{
"_percolator_document_slot":[
0
]
},
"highlight":{
"title":[
"<em>A</em> new <em>bonsai</em> <em>tree</em> <em>in</em> <em>the</em> office and <em>jungle</em>"
]
}
}
]
}
}
如你所见,从字面上看,丛林中的三个盆景不等于办公室和丛林中的新盆景树。但它匹配了我的percolate查询中的每个单词。为什么会这样?
- 然后我添加新的percolate查询
醇>
curl -X PUT "localhost:9200/my-index/_doc/2?refresh" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"title" : "the enojen tree in a kerojen"
}
}
}
'
和新搜索:
curl -X GET "localhost:9200/my-index/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field": "query",
"document" : {
"title" : "A new bonsai tree in the office and jungle. The enojen tree in a kerojen."
}
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
'
输出:
{
"took":12,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":45,
"max_score":2.1576157,
"hits":[
{
"_index":"my-index",
"_type":"_doc",
"_id":"2",
"_score":2.1576157,
"_source":{
"query":{
"match":{
"title":"the enojen tree in a kerojen"
}
}
},
"fields":{
"_percolator_document_slot":[
0
]
},
"highlight":{
"title":[
"<em>A</em> new bonsai <em>tree</em> <em>in</em> <em>the</em> office and jungle. <em>The</em> <em>enojen</em> <em>tree</em> <em>in</em> <em>a</em> <em>kerojen</em>."
]
}
},
{
"_index":"my-index",
"_type":"_doc",
"_id":"1",
"_score":2.1576157,
"_source":{
"query":{
"match":{
"title":"the bonsai tree in a jungle"
}
}
},
"fields":{
"_percolator_document_slot":[
0
]
},
"highlight":{
"title":[
"<em>A</em> new <em>bonsai</em> <em>tree</em> <em>in</em> <em>the</em> office and <em>jungle</em>. <em>The</em> enojen <em>tree</em> <em>in</em> <em>a</em> kerojen."
]
}
}
]
}
}
当你看到两个不同的匹配但我想在搜索中组合我的两个percolate查询。不可能吗?
- (无法访问此步骤)使用
醇>pre-tag
更改post-tag
和<em></em>
<a href="$var"></a>
并更改$var
有一些代码。
最后,
- 所有文档都将显示在带有超链接的html页面中。 (希望:))
醇>
我有可能做的事吗?如果没有,你能解释哪一部分不能完成吗?如果有可能,你能给我一些建议吗?如何改进?