# Java API substring matching

**URL:** <https://discuss.elastic.co/t/java-api-substring-matching/24225>\
**Category:** Elasticsearch\
**Created:** [June 23, 2015, 10:46pm UTC](https://discuss.elastic.co/t/java-api-substring-matching/24225 "2015-06-23T22:46:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathaniel](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@nathaniel](https://discuss.elastic.co/u/nathaniel)\
**Post date:** [June 23, 2015, 10:46pm UTC](https://discuss.elastic.co/t/java-api-substring-matching/24225/1 "2015-06-23T22:46:14Z")

</div>

Hello guys, I am a new starter to elasticsearch. I am trying to use Java API to search and retrieve files.  
The problem is, i cannot figure out a good way to do the substring searching.

For example, if the file's content is :

"aaaa-bbbb-cccc"

then I can use the "matchQuery()" or "regexpQuery()" to search for "aaaa" or "bbbb" and get the target file.  
However, if the file's content change to :

"aaaa.bbbb.cccc"

I just cannot search for it with a substring! No matter I use matchQuery or regexpQuery or any other kinds of queries, I cannot get this file by searching "aaaa", "bbbb", or "cccc".

I don't understand why this is happening, because If i use Kibana and search from the gui, I can get the satisfying result.

Would any guys help me out please? I really appreciate that. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [June 24, 2015, 8:08am UTC](https://discuss.elastic.co/t/java-api-substring-matching/24225/2 "2015-06-24T08:08:42Z")

</div>

I assume your are using the default analyzer ([standard analyzer](http://lucene.apache.org/core/4_0_0/analyzers-common/org/apache/lucene/analysis/standard/StandardAnalyzer.html)) to index the field. The standard analyzer does not split the term on the full stop characters during the analysis process. You can test this out using the [Analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html):

```
curl -XGET 'localhost:9200/{index_name}/_analyze?analyzer=standard&pretty=true' -d 'aaaa.bbbb.cccc'

```

The [simple analyzer](http://lucene.apache.org/core/4_0_0/analyzers-common/org/apache/lucene/analysis/core/SimpleAnalyzer.html) does split the term on the full stop character:

```
curl -XGET 'localhost:9200/{index_name}/_analyze?analyzer=simple&pretty=true' -d 'aaaa.bbbb.cccc'

```

In your [index mapping](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html) specify the `simple analyzer` for the field and and re-index the document.

---

<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, 12:05am UTC](https://discuss.elastic.co/t/java-api-substring-matching/24225/3 "2017-07-06T00:05:44Z")

</div>


