Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:14:08+00:00 2026-05-30T13:14:08+00:00

I have a simple sounding problem according highlighting of a field with elasticsearch version

  • 0

I have a simple sounding problem according highlighting of a field with elasticsearch version 0.18.6. What I want to do is to highlight a complete field and get the content back (either highlighted or if there are no matches then without highlighting – but always the full field content!)

On elasticsearch.org I found this:

If the number_of_fragments value is set to 0 then no fragments are produced, instead the whole content of the field is returned, and of course it is highlighted.

So I tried this to achieve what I want:

  final SearchResponse response = client.prepareSearch(indexName)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setTypes(FEED_TYPE)
                .setQuery(queryString(query).field("title").field("description").field("keywords"))
                .addHighlightedField("title", 0, 0)
                .addHighlightedField("description", 0, 0)
                .addFields("url", "iconUrl", "keywords")
                .setSize(size)
                .setFrom(start)
                .execute().actionGet();

The Signature of this method is:

 public SearchRequestBuilder addHighlightedField(java.lang.String name, int fragmentSize, int numberOfFragments)

Do I miss something here? Or did I misunderstand that it only returns the full content if there is at least one term to hightlight?

Thanks for all answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:14:09+00:00Added an answer on May 30, 2026 at 1:14 pm

    I don’t think it’s possible to achieve exactly what you want at the moment. The highlightFields collection contains only fields that were highlighted. You can do something like this:

    final SearchResponse response = client.prepareSearch(indexName)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setTypes(FEED_TYPE)
                .setQuery(queryString(query).field("title").field("description").field("keywords"))
                .addHighlightedField("title", 0, 0)
                .addHighlightedField("description", 0, 0)
                .addFields("title", "description", "url", "iconUrl", "keywords")
                .setSize(size)
                .setFrom(start)
                .execute().actionGet();
    

    It will always return you all fields in

    response.hits().getAt(i).fields();
    

    and fields that were highlighted in

    response.hits().getAt(i).highlightFields();
    

    While displaying results, you can check highlightFields() first and if a field is not present there, use fields() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple script, I want to get my images and then divide them
I have simple CI (CodeIgniter) code. what I want to do is: when I
I have simple aspx page that has a form and a input field in
I have simple problem: class Weapon{ public: int dmg; float speed; int rate; };
I have simple problem as I am not much familiar with Java GUI. I
I have simple form posting to another file. The problem I'm having is with
I have simple app in my project. This app works without any problem. I
I have simple base class with single static field. I have numerous classes that
I have simple one column HTML files ( ebooks from Gutenberg Project). I want
We have simple div as below. The problem here there is gap between the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.