# Highlighting with terms query  StringIndexOutOfBoundsException on 1 shard

**URL:** <https://discuss.elastic.co/t/highlighting-with-terms-query-stringindexoutofboundsexception-on-1-shard/9024>\
**Category:** Elasticsearch\
**Created:** [September 14, 2012, 11:44am UTC](https://discuss.elastic.co/t/highlighting-with-terms-query-stringindexoutofboundsexception-on-1-shard/9024 "2012-09-14T11:44:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_D](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Matt\_D](https://discuss.elastic.co/u/Matt_D)\
**Post date:** [September 14, 2012, 11:44am UTC](https://discuss.elastic.co/t/highlighting-with-terms-query-stringindexoutofboundsexception-on-1-shard/9024/1 "2012-09-14T11:44:23Z")

</div>

So I'm just starting out with ElasticaSearch so I'm still learning the  
ropes, but as the title states in this particular occurance I'm getting an  
exception back from my query. Any help would be greatly appreciated.

{  
"query": {  
"terms": {  
"message": [  
"call",  
"publication"  
]  
}  
},  
"size": 10,  
"highlight": {  
"pre\_tags": [  
""  
],  
"post\_tags": [  
""  
],  
"fields": {  
"message": {  
"fragment\_size": 200,  
"number\_of\_fragments": 1,  
"term\_vector": "with\_positions\_offsets"  
}  
}  
}  
}

And when I try to run it I get the following error from one of my shards.  
If I run it with the terms individually it displays as I would expect it to.

- timed\_out: false
- \_shards: {
  - total: 5
  - successful: 4
  - failed: 1
  - failures: [
    - {
      - index: index\_30000
      - shard: 0
      - status: 500
      - reason: FetchPhaseExecutionException[[index\_30000][0]:  
query[message:call message:publication],from[0],size[10]: Fetch Failed  
[Failed to highlight field [message]]]; nested:  
StringIndexOutOfBoundsException[String index out of range: -30];  
}  
]  
}

Finally I'm using the following String & search analyzers in the index  
'number\_of\_shards' =\> 5,  
'number\_of\_replicas' =\> 1,  
'analysis' =\> array(  
'analyzer' =\> array(  
'str\_index\_analyzer' =\> array(  
'tokenizer' =\> 'keyword',  
'filter' =\> array('lowercase', 'substring')  
),  
'str\_search\_analyzer' =\> array(  
'tokenizer' =\> 'keyword',  
'filter' =\> array('lowercase')  
)  
),  
'filter' =\> array(  
'substring' =\> array(  
'type' =\> 'nGram',  
'min\_gram' =\> 1,  
'max\_gram' =\> 20  
)  
)  
)

And this is the mapping for that particular field.  
'message' =\> array(  
'type' =\> 'string',  
'index\_analyzer' =\> 'str\_index\_analyzer',  
'search\_analyzer' =\> 'str\_search\_analyzer',  
'store' =\> 'yes',  
'term\_vector' =\> 'with\_positions\_offsets'  
)

--

---

<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, 3:12am UTC](https://discuss.elastic.co/t/highlighting-with-terms-query-stringindexoutofboundsexception-on-1-shard/9024/2 "2017-07-06T03:12:45Z")

</div>


