use of org.elasticsearch.action.search.SearchResponse 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.search.SearchResponse in project elasticsearch by elastic.
the class SimpleQueryStringIT method testWithDate.
public void testWithDate() throws Exception {
String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json");
prepareCreate("test").setSource(indexBody, XContentType.JSON).get();
ensureGreen("test");
List<IndexRequestBuilder> reqs = new ArrayList<>();
reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo", "f_date", "2015/09/02"));
reqs.add(client().prepareIndex("test", "doc", "2").setSource("f1", "bar", "f_date", "2015/09/01"));
indexRandom(true, false, reqs);
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo bar")).get();
assertHits(resp.getHits(), "1", "2");
assertHitCount(resp, 2L);
resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("\"2015/09/02\"")).get();
assertHits(resp.getHits(), "1");
assertHitCount(resp, 1L);
resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("bar \"2015/09/02\"")).get();
assertHits(resp.getHits(), "1", "2");
assertHitCount(resp, 2L);
resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("\"2015/09/02\" \"2015/09/01\"")).get();
assertHits(resp.getHits(), "1", "2");
assertHitCount(resp, 2L);
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SimpleQueryStringIT method testSimpleQueryStringFlags.
public void testSimpleQueryStringFlags() throws ExecutionException, InterruptedException {
createIndex("test");
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("body", "foo"), client().prepareIndex("test", "type1", "2").setSource("body", "bar"), client().prepareIndex("test", "type1", "3").setSource("body", "foo bar"), client().prepareIndex("test", "type1", "4").setSource("body", "quux baz eggplant"), client().prepareIndex("test", "type1", "5").setSource("body", "quux baz spaghetti"), client().prepareIndex("test", "type1", "6").setSource("otherbody", "spaghetti"));
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo bar").flags(SimpleQueryStringFlag.ALL)).get();
assertHitCount(searchResponse, 3L);
assertSearchHits(searchResponse, "1", "2", "3");
searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo | bar").defaultOperator(Operator.AND).flags(SimpleQueryStringFlag.OR)).get();
assertHitCount(searchResponse, 3L);
assertSearchHits(searchResponse, "1", "2", "3");
searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo | bar").defaultOperator(Operator.AND).flags(SimpleQueryStringFlag.NONE)).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("baz | egg*").defaultOperator(Operator.AND).flags(SimpleQueryStringFlag.NONE)).get();
assertHitCount(searchResponse, 0L);
searchResponse = client().prepareSearch().setSource(new SearchSourceBuilder().query(QueryBuilders.simpleQueryStringQuery("foo|bar").defaultOperator(Operator.AND).flags(SimpleQueryStringFlag.NONE))).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("quuz~1 + egg*").flags(SimpleQueryStringFlag.WHITESPACE, SimpleQueryStringFlag.AND, SimpleQueryStringFlag.FUZZY, SimpleQueryStringFlag.PREFIX)).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("4"));
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SimpleQueryStringIT method testSimpleQueryStringOnIndexMetaField.
public void testSimpleQueryStringOnIndexMetaField() 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("test").field("_index")).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "2");
}
use of org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SimpleQueryStringIT method testLenientFlagBeingTooLenient.
// Issue #7967
public void testLenientFlagBeingTooLenient() throws Exception {
indexRandom(true, client().prepareIndex("test", "doc", "1").setSource("num", 1, "body", "foo bar baz"), client().prepareIndex("test", "doc", "2").setSource("num", 2, "body", "eggplant spaghetti lasagna"));
BoolQueryBuilder q = boolQuery().should(simpleQueryStringQuery("bar").field("num").field("body").lenient(true));
SearchResponse resp = client().prepareSearch("test").setQuery(q).get();
assertNoFailures(resp);
// the bug is that this would be parsed into basically a match_all
// query and this would match both documents
assertHitCount(resp, 1);
assertSearchHits(resp, "1");
}
Aggregations