# Index phrase query as percolator

**URL:** <https://discuss.elastic.co/t/index-phrase-query-as-percolator/129932>\
**Category:** Elasticsearch\
**Created:** [April 28, 2018, 8:53pm UTC](https://discuss.elastic.co/t/index-phrase-query-as-percolator/129932 "2018-04-28T20:53:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keremcan](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@keremcan](https://discuss.elastic.co/u/keremcan)\
**Post date:** [April 28, 2018, 8:53pm UTC](https://discuss.elastic.co/t/index-phrase-query-as-percolator/129932/1 "2018-04-28T20:53:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![keremcan](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@keremcan](https://discuss.elastic.co/u/keremcan)\
**Post date:** [May 6, 2018, 3:45pm UTC](https://discuss.elastic.co/t/index-phrase-query-as-percolator/129932/2 "2018-05-06T15:45:57Z")

</div>

Any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 3, 2018, 3:46pm UTC](https://discuss.elastic.co/t/index-phrase-query-as-percolator/129932/3 "2018-06-03T15:46:09Z")

</div>

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