# Configuring the default analyzer using the Java API not working

**URL:** https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871
**Category:** Elasticsearch
**Created:** [July 15, 2011, 2:11pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871 "2011-07-15T14:11:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Spring\_Ninja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spring_ninja/32/2719_2.png) [@Spring\_Ninja](https://discuss.elastic.co/u/Spring_Ninja)
#### Post date: [July 15, 2011, 2:11pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/1 "2011-07-15T14:11:23Z")

</div>

Hi there all...

I run ES embedded in my application. Below is the code I use to create  
the node and client, and configure the default analyzer.

Then the code I use to parse a free text query. The analyzer returned  
is not the one configured as expected. In fact, if I put breakpoints  
in both ES WhitespaceTokenizerFactory and Lucene WhitespaceTokenizer,  
none are used.

Questions I have:

- Do I need to explicitly define the default\_index and default\_search  
analyzers?
- When doing such a settings request, do I add to the current  
configuration or do I overwrite the complete analysis config,  
effectively obliterating the whitespace tokenizer declaration?
- Is there a better way to create this configuration. Is there a way  
to initialize the embedded ES node with a YML config, the same way a  
standalone ES reads from ES\_HOME/config?

Thanks all!

Remy

---

<div class="post-metadata">

### Author: ![Spring\_Ninja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spring_ninja/32/2719_2.png) [@Spring\_Ninja](https://discuss.elastic.co/u/Spring_Ninja)
#### Post date: [July 15, 2011, 2:18pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/2 "2011-07-15T14:18:03Z")

</div>

Sorry, here's the code:

Properties esProperties = new Properties();

... esProperties filled from my app config.

```
    // Create the ES node and client.

    Settings nodeSettings =

```

ImmutableSettings.settingsBuilder().put(esProperties).build();  
elasticSearchNode =  
NodeBuilder.nodeBuilder().settings(nodeSettings).node();  
elasticSearchClient = elasticSearchNode.client();

```
    // Default index and analyzer configuration.

    XContentBuilder indexSettings = null;
    try
    {
        indexSettings = XContentFactory.jsonBuilder();

```

indexSettings.startObject().startObject("index").startObject("analysis").startObject("analyzer")  
.startObject("default").field("type",  
"custom").field("tokenizer", "whitespace")  
.field("filter", new String[] { "asciifolding",  
"lowercase" }).endObject().endObject().endObject()  
.endObject().endObject();

```
        logger.info(indexSettings.string());

        UpdateSettingsRequestBuilder settingsRequest =

```

elasticSearchClient.admin().indices()  
.prepareUpdateSettings();  
settingsRequest.setSettings(indexSettings.string());  
UpdateSettingsResponse settingsResponse =  
settingsRequest.execute().actionGet();  
ValidateState.notNull(settingsResponse);  
}  
catch (IOException e)  
{  
ValidateState.fail();  
}

And the snippet where I tokenize the user query:

```
    /*
     * Process the assembled query string one token at a time. The

```

provided analyser must tokenize the query the  
\* same way it was done (or in a compatible fashion if you  
know what you are doing) when the indexing took  
\* place.  
\*/

```
    EntityInfo entityInfo = getEntityInfo(entityFilters.get(0));

    // Allow this clause to be added as an AND to an existing

```

query.

```
    BoolQueryBuilder subQuery = QueryBuilders.boolQuery();

    AnalyzeRequestBuilder arb =

```

elasticSearchClient.admin().indices()  
.prepareAnalyze(entityInfo.logicalName,  
termsAsString);  
// This will use the default analyzer configured for all  
indices.  
AnalyzeResponse analysis = arb.execute().actionGet();  
for (AnalyzeToken token : analysis.getTokens())  
{  
String term = token.getTerm();  
if (StringUtils.isNotEmpty(term))  
{  
...

There I see that the whitespace tokenizer is not called...

Thanks!

---

<div class="post-metadata">

### Author: ![Spring\_Ninja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spring_ninja/32/2719_2.png) [@Spring\_Ninja](https://discuss.elastic.co/u/Spring_Ninja)
#### Post date: [July 15, 2011, 3:20pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/3 "2011-07-15T15:20:13Z")

</div>

Solved my issue by loading the analysis config from a properties file  
and passing it to the NodeBuilder directly.

Was I too late in using the client to make an update settings request.

R.

---

<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: [July 15, 2011, 6:16pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/4 "2011-07-15T18:16:25Z")

</div>

ITs hard to read the code, can you gist it?

On Friday, July 15, 2011 at 6:20 PM, Spring Ninja wrote:

> Solved my issue by loading the analysis config from a properties file  
> and passing it to the NodeBuilder directly.
> 
> Was I too late in using the client to make an update settings request.
> 
> R.

---

<div class="post-metadata">

### Author: ![Spring\_Ninja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spring_ninja/32/2719_2.png) [@Spring\_Ninja](https://discuss.elastic.co/u/Spring_Ninja)
#### Post date: [July 15, 2011, 6:32pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/5 "2011-07-15T18:32:22Z")

</div>

[https://gist.github.com/1085232](https://gist.github.com/1085232)

---

<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: [July 24, 2011, 3:15am UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/6 "2011-07-24T03:15:09Z")

</div>

You need to provide those settings when you create the index, you can't  
update them once the index is open. You can update them if the index is  
closed.

On Fri, Jul 15, 2011 at 9:32 PM, Spring Ninja [remy.gendron@ingeno.ca](mailto:remy.gendron@ingeno.ca)wrote:

> [https://gist.github.com/1085232](https://gist.github.com/1085232)

---

<div class="post-metadata">

### Author: ![sky\_lyfe](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@sky\_lyfe](https://discuss.elastic.co/u/sky_lyfe)
#### Post date: [December 22, 2011, 8:14pm UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/7 "2011-12-22T20:14:51Z")

</div>

hey ninja,  
can you give an example on how you loaded the config from a properties file...  
code snippet maybe.  
i am having the same issue.  
my custom analyzers are not being recognized  
advTHANKSance  
-skylyfe

---

<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:44am UTC](https://discuss.elastic.co/t/configuring-the-default-analyzer-using-the-java-api-not-working/4871/8 "2017-07-06T03:44:32Z")

</div>


