3

I am using Elastic search, and not able to do phrase search on the attributes on which custom analyzer is applied.

Custom analyzer is mentioned as:

"settings" : {
        "analysis.analyzer.string_lowercase.type" : "custom",
        "analysis.analyzer.string_lowercase.tokenizer" : "keyword",
        "analysis.analyzer.string_lowercase.filter" : "lowercase"
}

Attribute value is like : "into the puddle, out of the puddle", or could be any String.

I have tried using following:

1) **(Not worked)** QueryBuilders.queryString("*into the puddle*").autoGeneratePhraseQueries(true).defaultOperator(Operator.AND);

2) **(Not worked)** QueryBuilders.matchPhraseQuery(attribute, "into the puddle");

3) **(Not worked)** QueryBuilders.queryString("*into the puddle*").autoGeneratePhraseQueries(true).defaultOperator(Operator.AND).analyzeWildcard(true);

But, fortunately try 1, works fine with the nested objects.

FilterBuilders.nestedFilter(attribute, queryString("*into the puddle*").field(attribute)
                                .defaultOperator(Operator.AND).analyzeWildcard(true));
anks2089
  • 57
  • 1
  • 8

1 Answers1

1

1) - 3) seem to be missing a field and therefore are searching the _all field, which I would guess is indexed using standard analyzer.

imotov
  • 28,277
  • 3
  • 90
  • 82
  • Hi Imotov, even after mentioning standard analyzer in the query explicitly. It won't give any results. – anks2089 Nov 12 '12 at 11:30
  • 1
    Applying analyzer to the query wouldn't help since your field is indexed as a single token, and standard analyzer splits query into multiple tokens, which really reduces chances of finding anything. If you want to use phrases and standard analyzer, switch to standard analyzer during indexing. If you want keyword analyzer, use wildcard query instead. Or better yet take a look at ngrams http://stackoverflow.com/a/6471449/783043 Leading wildcards might be really problematic on large indices. – imotov Nov 13 '12 at 05:31