索引短语查询为过滤器

时间:2018-04-29 08:39:24

标签: elasticsearch elasticsearch-percolate

我正在尝试渗透一些文本并添加匹配的超链接。但在添加超链接之前,我无法想象如何突出显示多个单词。以下是该场景的快乐路径:

  
      
  1. 像这样添加映射:
  2.   
curl -X PUT "localhost:9200/my-index" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "_doc": {
            "properties": {
                "message": {
                    "type": "text"
                },
                "query": {
                    "type": "percolator"
                }
            }
        }
    }
}
'
  
      
  1. 在过滤器中注册查询
  2.   
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"
        }
    }
}
'
  
      
  1. 使用我的percolate查询突出显示的新文档
  2.   
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查询中的每个单词。为什么会这样?

  
      
  1. 然后我添加新的percolate查询
  2.   
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查询。不可能吗?

  
      
  1. 无法访问此步骤)使用pre-tag更改post-tag<em></em> <a href="$var"></a>并更改$var   有一些代码。
  2.   

最后,

  
      
  1. 所有文档都将显示在带有超链接的html页面中。 (希望:))
  2.   

我有可能做的事吗?如果没有,你能解释哪一部分不能完成吗?如果有可能,你能给我一些建议吗?如何改进?

0 个答案:

没有答案