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!