use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.
the class SimpleQueryStringIT method testSimpleQueryStringAnalyzeWildcard.
public void testSimpleQueryStringAnalyzeWildcard() throws ExecutionException, InterruptedException, IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "text").field("analyzer", "german").endObject().endObject().endObject().endObject().string();
CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test1").addMapping("type1", mapping, XContentType.JSON);
mappingRequest.execute().actionGet();
indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("location", "Köln"));
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("Köln*").field("location")).get();
assertNoFailures(searchResponse);
assertHitCount(searchResponse, 1L);
assertSearchHits(searchResponse, "1");
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.
the class SuggestSearchIT method testSuggestWithManyCandidates.
public void testSuggestWithManyCandidates() throws InterruptedException, ExecutionException, IOException {
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, // A single shard will help to keep the tests repeatable.
1).put("index.analysis.analyzer.text.tokenizer", "standard").putArray("index.analysis.analyzer.text.filter", "lowercase", "my_shingle").put("index.analysis.filter.my_shingle.type", "shingle").put("index.analysis.filter.my_shingle.output_unigrams", true).put("index.analysis.filter.my_shingle.min_shingle_size", 2).put("index.analysis.filter.my_shingle.max_shingle_size", 3));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("title").field("type", "text").field("analyzer", "text").endObject().endObject().endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
List<String> titles = new ArrayList<>();
// We're going to be searching for:
// united states house of representatives elections in washington 2006
// But we need to make sure we generate a ton of suggestions so we add a bunch of candidates.
// Many of these candidates are drawn from page names on English Wikipedia.
// Tons of different options very near the exact query term
titles.add("United States House of Representatives Elections in Washington 1789");
for (int year = 1790; year < 2014; year += 2) {
titles.add("United States House of Representatives Elections in Washington " + year);
}
// since 0. Why not?
for (int year = 0; year < 2015; year++) {
titles.add(Integer.toString(year));
}
// That ought to provide more less good candidates for the last term
// Now remove or add plural copies of every term we can
titles.add("State");
titles.add("Houses of Parliament");
titles.add("Representative Government");
titles.add("Election");
// Now some possessive
titles.add("Washington's Birthday");
// And some conjugation
titles.add("Unified Modeling Language");
titles.add("Unite Against Fascism");
titles.add("Stated Income Tax");
titles.add("Media organizations housed within colleges");
// And other stuff
titles.add("Untied shoelaces");
titles.add("Unit circle");
titles.add("Untitled");
titles.add("Unicef");
titles.add("Unrated");
titles.add("UniRed");
// Highway in Malaysia
titles.add("Jalan Uniten–Dengkil");
titles.add("UNITAS");
titles.add("UNITER");
titles.add("Un-Led-Ed");
titles.add("STATS LLC");
titles.add("Staples");
titles.add("Skates");
titles.add("Statues of the Liberators");
titles.add("Staten Island");
titles.add("Statens Museum for Kunst");
// The last name or the German word, whichever.
titles.add("Hause");
titles.add("Hose");
titles.add("Hoses");
titles.add("Howse Peak");
titles.add("The Hoose-Gow");
titles.add("Hooser");
titles.add("Electron");
titles.add("Electors");
titles.add("Evictions");
titles.add("Coronal mass ejection");
// A film?
titles.add("Wasington");
// A town in England
titles.add("Warrington");
// Lots of places have this name
titles.add("Waddington");
// Ditto
titles.add("Watlington");
// Yup, also a town
titles.add("Waplington");
// Book
titles.add("Washing of the Spears");
for (char c = 'A'; c <= 'Z'; c++) {
// Can't forget lists, glorious lists!
titles.add("List of former members of the United States House of Representatives (" + c + ")");
// Lots of people are named Washington <Middle Initial>. LastName
titles.add("Washington " + c + ". Lastname");
// Lets just add some more to be evil
titles.add("United " + c);
titles.add("States " + c);
titles.add("House " + c);
titles.add("Elections " + c);
titles.add("2006 " + c);
titles.add(c + " United");
titles.add(c + " States");
titles.add(c + " House");
titles.add(c + " Elections");
titles.add(c + " 2006");
}
List<IndexRequestBuilder> builders = new ArrayList<>();
for (String title : titles) {
builders.add(client().prepareIndex("test", "type1").setSource("title", title));
}
indexRandom(true, builders);
PhraseSuggestionBuilder suggest = phraseSuggestion("title").addCandidateGenerator(candidateGenerator("title").suggestMode("always").maxTermFreq(.99f).size(// Setting a silly high size helps of generate a larger list of candidates for testing.
1000).maxInspections(// This too
1000)).confidence(0f).maxErrors(2f).shardSize(30000).size(30000);
Suggest searchSuggest = searchSuggest("united states house of representatives elections in washington 2006", "title", suggest);
assertSuggestion(searchSuggest, 0, 0, "title", "united states house of representatives elections in washington 2006");
// Just to prove that we've run through a ton of options
assertSuggestionSize(searchSuggest, 0, 25480, "title");
suggest.size(1);
long start = System.currentTimeMillis();
searchSuggest = searchSuggest("united states house of representatives elections in washington 2006", "title", suggest);
long total = System.currentTimeMillis() - start;
assertSuggestion(searchSuggest, 0, 0, "title", "united states house of representatives elections in washington 2006");
// assertThat(total, lessThan(1000L)); // Takes many seconds without fix - just for debugging
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.
the class SuggestSearchIT method testSizeParam.
public void testSizeParam() throws IOException {
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put("index.analysis.analyzer.reverse.tokenizer", "standard").putArray("index.analysis.analyzer.reverse.filter", "lowercase", "reverse").put("index.analysis.analyzer.body.tokenizer", "standard").putArray("index.analysis.analyzer.body.filter", "lowercase").put("index.analysis.analyzer.bigram.tokenizer", "standard").putArray("index.analysis.analyzer.bigram.filter", "my_shingle", "lowercase").put("index.analysis.filter.my_shingle.type", "shingle").put("index.analysis.filter.my_shingle.output_unigrams", false).put("index.analysis.filter.my_shingle.min_shingle_size", 2).put("index.analysis.filter.my_shingle.max_shingle_size", 2));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("body").field("type", "text").field("analyzer", "body").endObject().startObject("body_reverse").field("type", "text").field("analyzer", "reverse").endObject().startObject("bigram").field("type", "text").field("analyzer", "bigram").endObject().endObject().endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
String line = "xorr the god jewel";
index("test", "type1", "1", "body", line, "body_reverse", line, "bigram", line);
line = "I got it this time";
index("test", "type1", "2", "body", line, "body_reverse", line, "bigram", line);
refresh();
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("bigram").realWordErrorLikelihood(0.95f).gramSize(2).analyzer("body").addCandidateGenerator(candidateGenerator("body").minWordLength(1).prefixLength(1).suggestMode("always").size(1).accuracy(0.1f)).smoothingModel(new StupidBackoff(0.1)).maxErrors(1.0f).size(5);
Suggest searchSuggest = searchSuggest("Xorr the Gut-Jewel", "simple_phrase", phraseSuggestion);
assertSuggestionSize(searchSuggest, 0, 0, "simple_phrase");
// we allow a size of 2 now on the shard generator level so "god" will be found since it's LD2
phraseSuggestion.clearCandidateGenerators().addCandidateGenerator(candidateGenerator("body").minWordLength(1).prefixLength(1).suggestMode("always").size(2).accuracy(0.1f));
searchSuggest = searchSuggest("Xorr the Gut-Jewel", "simple_phrase", phraseSuggestion);
assertSuggestion(searchSuggest, 0, "simple_phrase", "xorr the god jewel");
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.
the class MatchQueryIT method setUp.
/**
* Test setup.
*/
@Before
public void setUp() throws Exception {
super.setUp();
CreateIndexRequestBuilder builder = prepareCreate(INDEX).setSettings(Settings.builder().put(indexSettings()).put("index.analysis.filter.syns.type", "synonym").putArray("index.analysis.filter.syns.synonyms", "wtf, what the fudge", "foo, bar baz").put("index.analysis.analyzer.lower_syns.type", "custom").put("index.analysis.analyzer.lower_syns.tokenizer", "standard").putArray("index.analysis.analyzer.lower_syns.filter", "lowercase", "syns").put("index.analysis.filter.graphsyns.type", "synonym_graph").putArray("index.analysis.filter.graphsyns.synonyms", "wtf, what the fudge", "foo, bar baz").put("index.analysis.analyzer.lower_graphsyns.type", "custom").put("index.analysis.analyzer.lower_graphsyns.tokenizer", "standard").putArray("index.analysis.analyzer.lower_graphsyns.filter", "lowercase", "graphsyns"));
assertAcked(builder.addMapping(INDEX, createMapping()));
ensureGreen();
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.
the class IndexAliasesIT method testCreateIndexWithAliasesFilterNotValid.
public void testCreateIndexWithAliasesFilterNotValid() {
//non valid filter, invalid json
CreateIndexRequestBuilder createIndexRequestBuilder = prepareCreate("test").addAlias(new Alias("alias2").filter("f"));
try {
createIndexRequestBuilder.get();
fail("create index should have failed due to invalid alias filter");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [alias2]"));
}
//valid json but non valid filter
createIndexRequestBuilder = prepareCreate("test").addAlias(new Alias("alias2").filter("{ \"test\": {} }"));
try {
createIndexRequestBuilder.get();
fail("create index should have failed due to invalid alias filter");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [alias2]"));
}
}
Aggregations