use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SimpleQueryStringIT method testSimpleQueryStringUsesFieldAnalyzer.
public void testSimpleQueryStringUsesFieldAnalyzer() throws Exception {
client().prepareIndex("test", "type1", "1").setSource("foo", 123, "bar", "abc").get();
client().prepareIndex("test", "type1", "2").setSource("foo", 234, "bar", "bcd").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("123").field("foo").field("bar")).get();
assertHitCount(searchResponse, 1L);
assertSearchHits(searchResponse, "1");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class FieldSortIT method testIssue2986.
public void testIssue2986() {
assertAcked(client().admin().indices().prepareCreate("test").addMapping("type", "field1", "type=keyword").get());
client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}", XContentType.JSON).execute().actionGet();
client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}", XContentType.JSON).execute().actionGet();
client().prepareIndex("test", "post", "3").setSource("{\"field1\":\"value3\"}", XContentType.JSON).execute().actionGet();
refresh();
SearchResponse result = client().prepareSearch("test").setQuery(matchAllQuery()).setTrackScores(true).addSort("field1", SortOrder.ASC).execute().actionGet();
for (SearchHit hit : result.getHits()) {
assertFalse(Float.isNaN(hit.getScore()));
}
}
Aggregations