简体   繁体   中英

Can't Get Highlights to Work with ElasticSearch C# NEST

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>")
                 )
             )
         );

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM