# Problem highlighting with Groovy API

**URL:** <https://discuss.elastic.co/t/problem-highlighting-with-groovy-api/3718>\
**Category:** Elasticsearch\
**Created:** [December 31, 2010, 2:50am UTC](https://discuss.elastic.co/t/problem-highlighting-with-groovy-api/3718 "2010-12-31T02:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbro](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mbro](https://discuss.elastic.co/u/mbro)\
**Post date:** [December 31, 2010, 2:50am UTC](https://discuss.elastic.co/t/problem-highlighting-with-groovy-api/3718/1 "2010-12-31T02:50:20Z")

</div>

Hi,

I can't get highlighting to work with the Groovy API. Below are the  
request and response for both the REST API and the Groovy API. The  
REST API works fine.

REST REQUEST:  
curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
{  
"highlight" : {  
"fields" : {  
"\_all" : {}  
}  
},  
query : {  
term: {  
"user" : "kimchy"  
}  
}  
}  
'  
REST RESPONSE:  
"took":3,"\_shards":{"total":5,"successful":5,"failed":0},"hits":  
{"total":1,"max\_score":0.30685282,"hits":  
[{"\_index":"twitter","\_type":"tweet","\_id":"1","\_score":0.30685282,  
"\_source" :  
{  
"user" : "kimchy",  
"postDate" : "2009-11-15T14:12:12",  
"message" : "trying out Elastic Search"  
}  
,"highlight":{"\_all":["_kimchy_ 2009-11-15T14:12:12 trying  
out Elastic Search "]}}]}}

GROOVY REQUEST:  
def search = esClient.search {  
indices "twitter"  
source {  
query {  
query\_string (  
query : "kimchy"  
)  
}  
highlight : {  
fields : {  
\_all : {}  
}  
}  
}  
}

```
def results = search.response.hits.each { SearchHit hit ->
    println hit.dump()
}

```

GROOVY RESPONSE:  
\<org.elasticsearch.search.internal.InternalSearchHit@46decb41 docId=0  
score=0.06780553 id=1 type=tweet  
source=[10, 123, 10, 32, 32, 32, 32, 34, 117, 115, 101, 114, 34, 32,  
58, 32, 34, 107, 105, 109, 99, 104, 121, 34, 44, 10, 32, 32, 32, 32,  
34,  
112, 111, 115, 116, 68, 97, 116, 101, 34, 32, 58, 32, 34, 50, 48,  
48, 57, 45, 49, 49, 45, 49, 53, 84, 49, 52, 58, 49, 50, 58, 49, 50,  
34, 44,  
10, 32, 32, 32, 32, 34, 109, 101, 115, 115, 97, 103, 101, 34, 32,  
58,  
32, 34, 116, 114, 121, 105, 110, 103, 32, 111, 117, 116, 32, 69,  
108, 97, 115, 116, 105, 99, 32, 83, 101, 97, 114, 99, 104, 34, 10,  
125, 10]  
fields=[:] highlightFields=[:]  
sortValues=[] matchedFilters=[] explanation=null  
shard=[gCwC-CZSTpmkoshfcTidnQ][twitter][2] sourceAsMap=null\>

Here's the mapping I'm using:

curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
{  
"tweet" : {  
\_all : {type: "string", "store" : "yes", "term\_vector" :  
"with\_positions\_offsets"}  
}  
}  
}  
'

Thanks.

Mike

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 31, 2010, 9:10am UTC](https://discuss.elastic.co/t/problem-highlighting-with-groovy-api/3718/2 "2010-12-31T09:10:22Z")

</div>

Can you try without the ":" in the highlight element? Something like this:

def search = esClient.search {  
indices "twitter"  
source {  
query {  
query\_string (  
query : "kimchy"  
)  
}  
highlight {  
fields {  
\_all {}  
}  
}  
}  
}

On Fri, Dec 31, 2010 at 4:50 AM, Mike Brocious [mike.brocious@gmail.com](mailto:mike.brocious@gmail.com)wrote:

> Hi,
> 
> I can't get highlighting to work with the Groovy API. Below are the  
> request and response for both the REST API and the Groovy API. The  
> REST API works fine.
> 
> REST REQUEST:  
> curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
> {  
> "highlight" : {  
> "fields" : {  
> "\_all" : {}  
> }  
> },  
> query : {  
> term: {  
> "user" : "kimchy"  
> }  
> }  
> }  
> '  
> REST RESPONSE:  
> "took":3,"\_shards":{"total":5,"successful":5,"failed":0},"hits":  
> {"total":1,"max\_score":0.30685282,"hits":  
> [{"\_index":"twitter","\_type":"tweet","\_id":"1","\_score":0.30685282,  
> "\_source" :  
> {  
> "user" : "kimchy",  
> "postDate" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }  
> ,"highlight":{"\_all":["_kimchy_ 2009-11-15T14:12:12 trying  
> out Elastic Search "]}}]}}
> 
> GROOVY REQUEST:  
> def search = esClient.search {  
> indices "twitter"  
> source {  
> query {  
> query\_string (  
> query : "kimchy"  
> )  
> }  
> highlight : {  
> fields : {  
> \_all : {}  
> }  
> }  
> }  
> }
> 
> def results = search.response.hits.each { SearchHit hit -\>  
> println hit.dump()  
> }
> 
> GROOVY RESPONSE:  
> \<org.elasticsearch.search.internal.InternalSearchHit@46decb41 docId=0  
> score=0.06780553 id=1 type=tweet  
> source=[10, 123, 10, 32, 32, 32, 32, 34, 117, 115, 101, 114, 34, 32,  
> 58, 32, 34, 107, 105, 109, 99, 104, 121, 34, 44, 10, 32, 32, 32, 32,  
> 34,  
> 112, 111, 115, 116, 68, 97, 116, 101, 34, 32, 58, 32, 34, 50, 48,  
> 48, 57, 45, 49, 49, 45, 49, 53, 84, 49, 52, 58, 49, 50, 58, 49, 50,  
> 34, 44,  
> 10, 32, 32, 32, 32, 34, 109, 101, 115, 115, 97, 103, 101, 34, 32,  
> 58,  
> 32, 34, 116, 114, 121, 105, 110, 103, 32, 111, 117, 116, 32, 69,  
> 108, 97, 115, 116, 105, 99, 32, 83, 101, 97, 114, 99, 104, 34, 10,  
> 125, 10]  
> fields=[:] highlightFields=[:]  
> sortValues= matchedFilters= explanation=null  
> shard=[gCwC-CZSTpmkoshfcTidnQ][twitter][2] sourceAsMap=null\>
> 
> Here's the mapping I'm using:
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> {  
> "tweet" : {  
> \_all : {type: "string", "store" : "yes", "term\_vector" :  
> "with\_positions\_offsets"}  
> }  
> }  
> }  
> '
> 
> Thanks.
> 
> Mike

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:14am UTC](https://discuss.elastic.co/t/problem-highlighting-with-groovy-api/3718/3 "2017-07-06T04:14:36Z")

</div>

Closed on July 6, 2017, 4:14am UTC


