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 9142497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:47:47+00:00 2026-06-17T09:47:47+00:00

I have trouble getting elasticsearch results highlighting to work. I have found many examples

  • 0

I have trouble getting elasticsearch results highlighting to work. I have found many examples and tried different versions but I fail applying it to my own index. What am I doing wrong?

Here is my test script:

init() {
    curl -XDELETE http://localhost:9200/twitter
    echo
    curl -XPUT http://localhost:9200/twitter
    echo

    curl -XPUT http://localhost:9200/twitter/tweet/_mapping -d '{
        "tweet" : {
            "properties" : {
                "user" : { "type" : "string" },
                "message" : {
                    "type" : "string",
                    "index": "analyzed",
                    "store": "yes",
                    "term_vector" : "with_positions_offsets"
                 }
            }
        }
    }'
    echo
    curl -XPOST http://localhost:9200/twitter/tweet -d '{
        "user": "kimchy",
        "message": "You know, for Search"
    }'
    echo
    curl -XPOST http://localhost:9200/twitter/tweet -d '{
        "user": "bar",
        "message": "You know, foo for Search"
    }'
    echo

    sleep 2
    echo '-------------------'
}

[ "$1" = "init" ] && init

curl -X GET 'http://localhost:9200/twitter/_search/?pretty=true' -d '{
    "query":{
            "query_string":{
                "query":"foo"
            }
        }
    },
    "highlight":{
        "pre_tags": "<b>",
        "post_tags": "</b>",
        "fields" : {
            "message" : {"number_of_fragments": 20}
        }
    }
}'

and here the output:

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.09492774,
    "hits" : [ {
      "_index" : "twitter",
      "_type" : "tweet",
      "_id" : "1tgGWGhnRLy-nJIAunFeeQ",
      "_score" : 0.09492774, "_source" : {
        "user": "bar",
        "message": "You know, foo for Search"
    }
    } ]
  }
}%  

As you can see the highlight property is missing completely.

  • 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-06-17T09:47:48+00:00Added an answer on June 17, 2026 at 9:47 am

    You have too many closing curly brackets in your query part:

    "query":{
            "query_string":{
                "query":"foo"
            }
        } <---- This one is not needed.
    },
    

    So the highlight portion is simply ignored by parser.

    By the way, the pre_tags and post_tags should be arrays:

    curl "localhost:9200/twitter/tweet/_search?pretty=true" -d '{
        "query": {
            "query_string": {
                "query": "foo"
            }
        },
        "highlight": {
            "pre_tags": ["<b>"],
            "post_tags": ["</b>"],
            "fields": {
                "message": {"number_of_fragments": 20}
            }
        }    
    }' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble getting a custom ObjectDataSource for an asp:ListView control to work. I
This seemed like it should be easy, but I have had trouble getting it
I am having trouble getting the JSF annotations to work. I have spent some
Hi I am having trouble getting an embedded js file to work. I have
I am having trouble getting a Django ORM query to work correctly. I have
iI have some trouble getting sth like this to work in java: public class
I'm have trouble getting a project at work to run. The problem is that
I always, always have trouble getting jQuery to work in wordpress. I really need
Have som trouble getting the code below to work. I am trying to fire
I have some trouble getting position: relative to work in IE9. Here's a demo

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.