1

I'm trying to get highlights back from my searches using the code below. Despite trying all sorts of things the Highlights collection on the result is always empty.

Using ElasticSearch server 2.3.1 and NEST 2.3.0.

results = _client.Search<dynamic>( d =>
            d.AllIndices()
            .AllTypes()
            .Query( q => q.QueryString( s => s.Query( query ) ) )
            .Highlight(h => 
                 h.Fields( f => 
                    f.Field( "*" ).PreTags("<em>").PostTags("</em>")
                 )
             )
         );
Jon Edmiston
  • 950
  • 1
  • 9
  • 17
  • Take a look at the highlight usage examples - https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/highlighting-usage.html – Russ Cam May 15 '16 at 11:39
  • Do you have a succinct example to reproduce what you're seeing? – Russ Cam May 17 '16 at 03:24

2 Answers2

0

From my experience, to get the highlighter to return data with a * field request, you need to also provide it a copy of the query, within its own highlight query.

Pardon the native format, but here is an example that will yield hightlights from a * field pattern:

  "fields": {
     "*": {
        "highlight_query": {
           "query_string": {
              "query": "same as string query value"
           }
        }
     }
  }
Dexterama
  • 35
  • 6
0

I guess it is because you're using querystring. It your're querying multiple fields you can change that to MultipleMatch or if you're just querying 1 field you can use Match. Just take note about the special characters. Let say you're querying on Field1 but the query keyword(search keyword) is goes like this field2:"your keyword goes here" i dont think you can have any highlights on that.or probably you're getting the wrong result.

KarlM
  • 1