ElasticSearch partial word highlighting with Java API


(Shivang Sarawagi) #1

I am using elastic search java api version 1.6 in my app for searching data.

I wrote a query for the input search string

MatchQueryBuilder qb = QueryBuilders.matchQuery("_all", "search string");
SearchRequestBuilder srb =client.prepareSearch(index);
srb.addHighlightedField("name");
srb.setHighlighterPreTags("<b>");
srb.setHighlighterPostTags("</b>");
srb.setQuery(qb);

Below is the JSON query generated

{
  "size" : 10,
  "query" : {
    "filtered" : {
      "query" : {
        "match" : {
          "_all" : {
            "query" : "joh",
            "type" : "boolean"
          }
        }
      },
    }
  },
  "fields" : [ "name", "address", "level" ],
  "highlight" : {
    "pre_tags" : [ "<b>" ],
    "post_tags" : [ "</b>" ],
    "fields" : {
      "name" : { }
    }
  }
}

I am getting the partial word matches for the input search query string but the highlighting doesn't happen for partial word matches. Only the exact matches are getting highlighted.

Say I enter the word carro & the in the search results I get carrot. I only need the letters <b>carro</b>t
highlighted
How do I achieve partial highlight matches?


(system) #2