What is the equivalent of match_phrase_prefix in the Java API? I'm unable to find any classes that implement QueryBuilder that correspond to this?
I'm trying to set a custom analyzer for an index to also try search as you type during index time, but I'm having issues. I'm unable to change the analyzer setting for my index. Right now I'm giving it a json object with the settings, but it isn't going through. Could anyone provide an example on how to do it? I've copied this template: http://stackoverflow.com/questions/6275727/define-custom-elasticsearch-analyzer-using-java-api but it doesn't appear to work.
I'm expecting to receive
t
tr
try
tryi
tryin
trying
o
ou
out
but all I receive as tokens are "trying" and "out." I can't figure out how to setup the analyzer correctly.
I'm also wondering how I can do fuzzy queries with matchPhrasePrefixQuery. It seems like the fuzziness parameter doesn't work. Do I have to modify the search analyzer such that for every letter typed it tokenizes the current token with some degree of fuzziness?
Or would it be better to break down the words at index time using the above analyzer and use a fuzzy multimatchquery?
Thank you for the help, but I was unable to get that working.
What I'm doing at the moment is
client.admin().indices().preparePutMapping(indexName)
//set all the types in the index to adhere to this mapping, "_default_"
.setType("_default_")
.setSource(jsonBuilder()
//apply analyzer to all fields in the type. This is deprecated
.startObject()
.field("index_analyzer", "autocomplete")
.field("search_analyzer", "standard")
.endObject())
But I am reading that doing it like this is deprecated.
I tried this but was unable to get it to work. Could anything go wrong with using that specific deprecated feature? For all intents and purposes, it's working fine at the moment.
client.admin().indices().preparePutMapping(indexName)
//set all the types in the index to adhere to this mapping, "_default_"
.setType("_default_")
.setSource(jsonBuilder()
.startObject()
.startObject("dynamic_templates")
.startArray()
.startObject("template1")
.startObject()
.field("match", "*")
.startObject("mapping")
.field("type", "string")
.field("index_analyzer", "autocomplete")
.field("search_analyzer", "standard")
.endObject()
.endObject()
.endObject()
.endArray()
.endObject()
.endObject())
The documentation indicates that the body of the request should start with the type name. Try this instead:
client.admin().indices().preparePutMapping(indexName)
//set all the types in the index to adhere to this mapping, "_default_"
.setType("_default_")
.setSource(jsonBuilder()
.startObject()
.startObject("_default_")
.startObject("dynamic_templates")
.startArray()
.startObject("template1")
.startObject()
.field("match", "*")
.startObject("mapping")
.field("type", "string")
.field("index_analyzer", "autocomplete")
.field("search_analyzer", "standard")
.endObject()
.endObject()
.endObject()
.endArray()
.endObject()
.endObject()
.endObject())
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.