use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testQueryStringAnalyzedWildcard.
public void testQueryStringAnalyzedWildcard() throws Exception {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("value*")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue*")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue_1")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("val*e_1")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("v?l*e?1")).get();
assertHitCount(searchResponse, 1L);
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testDateRangeInQueryStringWithTimeZone_7880.
// Issue #7880
public void testDateRangeInQueryStringWithTimeZone_7880() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping("type", "past", "type=date"));
DateTimeZone timeZone = randomDateTimeZone();
String now = ISODateTimeFormat.dateTime().print(new DateTime(timeZone));
logger.info(" --> Using time_zone [{}], now is [{}]", timeZone.getID(), now);
client().prepareIndex("test", "type", "1").setSource("past", now).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-1m/m TO now+1m/m]").timeZone(timeZone.getID())).get();
assertHitCount(searchResponse, 1L);
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testNGramCopyField.
// see #5120
public void testNGramCopyField() {
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.analysis.analyzer.my_ngram_analyzer.type", "custom").put("index.analysis.analyzer.my_ngram_analyzer.tokenizer", "my_ngram_tokenizer").put("index.analysis.tokenizer.my_ngram_tokenizer.type", "nGram").put("index.analysis.tokenizer.my_ngram_tokenizer.min_gram", "1").put("index.analysis.tokenizer.my_ngram_tokenizer.max_gram", "10").putArray("index.analysis.tokenizer.my_ngram_tokenizer.token_chars", new String[0]));
assertAcked(builder.addMapping("test", "origin", "type=text,copy_to=meta", "meta", "type=text,analyzer=my_ngram_analyzer"));
// we only have ngrams as the index analyzer so searches will get standard analyzer
client().prepareIndex("test", "test", "1").setSource("origin", "C.A1234.5678").setRefreshPolicy(IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchQuery("meta", "1234")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(matchQuery("meta", "1234.56")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(termQuery("meta", "A1234")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(termQuery("meta", "a1234")).get();
// it's upper case
assertHitCount(searchResponse, 0L);
searchResponse = client().prepareSearch("test").setQuery(matchQuery("meta", "A1234").analyzer("my_ngram_analyzer")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(matchQuery("meta", "a1234").analyzer("my_ngram_analyzer")).get();
assertHitCount(searchResponse, 1L);
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testMultiMatchLenientIssue3797.
// see #3797
public void testMultiMatchLenientIssue3797() {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("field1", 123, "field2", "value2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true).useDisMax(false)).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(multiMatchQuery("value2", "field2").field("field1", 2).lenient(true).useDisMax(true)).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch("test").setQuery(multiMatchQuery("value2").field("field2", 2).lenient(true)).get();
assertHitCount(searchResponse, 1L);
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testAllDocsQueryString.
// see #3521
public void testAllDocsQueryString() throws InterruptedException, ExecutionException {
createIndex("test");
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("foo", "bar"), client().prepareIndex("test", "type1", "2").setSource("foo", "bar"));
int iters = scaledRandomIntBetween(100, 200);
for (int i = 0; i < iters; i++) {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("*:*^10.0").boost(10.0f)).get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch("test").setQuery(boolQuery().must(matchAllQuery()).must(constantScoreQuery(matchAllQuery()))).get();
assertHitCount(searchResponse, 2L);
assertThat((double) searchResponse.getHits().getAt(0).getScore(), closeTo(2.0, 0.1));
assertThat((double) searchResponse.getHits().getAt(1).getScore(), closeTo(2.0, 0.1));
}
}
Aggregations