Index phrase query as percolator


(Kerem Can) #1

Hi there! I'm trying to percolate some texts and add hyperlink to matches. But before adding hyperlink, I couldnt figure how to highlight words more than one. Here is my happy path:

  1. Adding mapping like this:
curl -X PUT "localhost:9200/my-index" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "_doc": {
            "properties": {
                "message": {
                    "type": "text"
                },
                "query": {
                    "type": "percolator"
                }
            }
        }
    }
}
'
  1. Register query in the 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"
        }
    }
}
'
  1. New doc to get highlighted with my percolate query
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": {}
      }
    }
}
'

Output:

{  
   "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>"
               ]
            }
         }
      ]
   }
}

as you see, literally, the bonsai three in a jungle can't equal A new bonsai tree in the office and jungle. But it matched every word in my percolate query. Why is happening like this?
4. And then I add new percolate query

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"
        }                 
    }                                                                  
}            
' 

and new search:

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": {}
      }
    }
}
'

output:

{  
   "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."
               ]
            }
         }
      ]
   }
}

as you see two different match but i want to combine my two percolate queries in the search. Can't it be possible?

  1. (This step couldn't be reached yet) Changing pre-tag and post-tag <em></em> with <a href="$var"></a> and changing $var with some codes.
  2. All docs will be displayed in html page with hyperlinks. (Hopefully:))

Is it possible what I'm trying to do? If not, could you explain which part can't be done? If it's possible, could you give me some advices how to do it and how to improve?


(Kerem Can) #2

Any suggestions?


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.