Search in sources :

Example 1 with SearchRequestBuilder

use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch by elastic.

the class EquivalenceIT method testRandomRanges.

// Make sure that unordered, reversed, disjoint and/or overlapping ranges are supported
// Duel with filters
public void testRandomRanges() throws Exception {
    final int numDocs = scaledRandomIntBetween(500, 5000);
    final double[][] docs = new double[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        final int numValues = randomInt(5);
        docs[i] = new double[numValues];
        for (int j = 0; j < numValues; ++j) {
            docs[i][j] = randomDouble() * 100;
        }
    }
    prepareCreate("idx").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties").startObject("values").field("type", "double").endObject().endObject().endObject().endObject()).execute().actionGet();
    for (int i = 0; i < docs.length; ++i) {
        XContentBuilder source = jsonBuilder().startObject().startArray("values");
        for (int j = 0; j < docs[i].length; ++j) {
            source = source.value(docs[i][j]);
        }
        source = source.endArray().endObject();
        client().prepareIndex("idx", "type").setSource(source).execute().actionGet();
    }
    assertNoFailures(client().admin().indices().prepareRefresh("idx").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get());
    final int numRanges = randomIntBetween(1, 20);
    final double[][] ranges = new double[numRanges][];
    for (int i = 0; i < ranges.length; ++i) {
        switch(randomInt(2)) {
            case 0:
                ranges[i] = new double[] { Double.NEGATIVE_INFINITY, randomInt(100) };
                break;
            case 1:
                ranges[i] = new double[] { randomInt(100), Double.POSITIVE_INFINITY };
                break;
            case 2:
                ranges[i] = new double[] { randomInt(100), randomInt(100) };
                break;
            default:
                throw new AssertionError();
        }
    }
    RangeAggregationBuilder query = range("range").field("values");
    for (int i = 0; i < ranges.length; ++i) {
        String key = Integer.toString(i);
        if (ranges[i][0] == Double.NEGATIVE_INFINITY) {
            query.addUnboundedTo(key, ranges[i][1]);
        } else if (ranges[i][1] == Double.POSITIVE_INFINITY) {
            query.addUnboundedFrom(key, ranges[i][0]);
        } else {
            query.addRange(key, ranges[i][0], ranges[i][1]);
        }
    }
    SearchRequestBuilder reqBuilder = client().prepareSearch("idx").addAggregation(query);
    for (int i = 0; i < ranges.length; ++i) {
        RangeQueryBuilder filter = QueryBuilders.rangeQuery("values");
        if (ranges[i][0] != Double.NEGATIVE_INFINITY) {
            filter = filter.from(ranges[i][0]);
        }
        if (ranges[i][1] != Double.POSITIVE_INFINITY) {
            filter = filter.to(ranges[i][1]);
        }
        reqBuilder = reqBuilder.addAggregation(filter("filter" + i, filter));
    }
    SearchResponse resp = reqBuilder.execute().actionGet();
    Range range = resp.getAggregations().get("range");
    List<? extends Bucket> buckets = range.getBuckets();
    HashMap<String, Bucket> bucketMap = new HashMap<>(buckets.size());
    for (Bucket bucket : buckets) {
        bucketMap.put(bucket.getKeyAsString(), bucket);
    }
    for (int i = 0; i < ranges.length; ++i) {
        long count = 0;
        for (double[] values : docs) {
            for (double value : values) {
                if (value >= ranges[i][0] && value < ranges[i][1]) {
                    ++count;
                    break;
                }
            }
        }
        final Range.Bucket bucket = bucketMap.get(Integer.toString(i));
        assertEquals(bucket.getKeyAsString(), Integer.toString(i), bucket.getKeyAsString());
        assertEquals(bucket.getKeyAsString(), count, bucket.getDocCount());
        final Filter filter = resp.getAggregations().get("filter" + i);
        assertThat(filter.getDocCount(), equalTo(count));
    }
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.range.Range.Bucket) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) HashMap(java.util.HashMap) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) Range(org.elasticsearch.search.aggregations.bucket.range.Range) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) Bucket(org.elasticsearch.search.aggregations.bucket.range.Range.Bucket) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with SearchRequestBuilder

use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch by elastic.

the class SearchFieldsIT method testScriptFields.

public void testScriptFields() throws Exception {
    assertAcked(prepareCreate("index").addMapping("type", "s", "type=keyword", "l", "type=long", "d", "type=double", "ms", "type=keyword", "ml", "type=long", "md", "type=double").get());
    final int numDocs = randomIntBetween(3, 8);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (int i = 0; i < numDocs; ++i) {
        reqs.add(client().prepareIndex("index", "type", Integer.toString(i)).setSource("s", Integer.toString(i), "ms", new String[] { Integer.toString(i), Integer.toString(i + 1) }, "l", i, "ml", new long[] { i, i + 1 }, "d", i, "md", new double[] { i, i + 1 }));
    }
    indexRandom(true, reqs);
    ensureSearchable();
    SearchRequestBuilder req = client().prepareSearch("index");
    for (String field : Arrays.asList("s", "ms", "l", "ml", "d", "md")) {
        req.addScriptField(field, new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + field + "'].values", Collections.emptyMap()));
    }
    SearchResponse resp = req.get();
    assertSearchResponse(resp);
    for (SearchHit hit : resp.getHits().getHits()) {
        final int id = Integer.parseInt(hit.getId());
        Map<String, SearchHitField> fields = hit.getFields();
        assertThat(fields.get("s").getValues(), equalTo(Collections.<Object>singletonList(Integer.toString(id))));
        assertThat(fields.get("l").getValues(), equalTo(Collections.<Object>singletonList((long) id)));
        assertThat(fields.get("d").getValues(), equalTo(Collections.<Object>singletonList((double) id)));
        assertThat(fields.get("ms").getValues(), equalTo(Arrays.<Object>asList(Integer.toString(id), Integer.toString(id + 1))));
        assertThat(fields.get("ml").getValues(), equalTo(Arrays.<Object>asList((long) id, id + 1L)));
        assertThat(fields.get("md").getValues(), equalTo(Arrays.<Object>asList((double) id, id + 1d)));
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Script(org.elasticsearch.script.Script) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) SearchHitField(org.elasticsearch.search.SearchHitField) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with SearchRequestBuilder

use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch by elastic.

the class HighlighterSearchIT method checkMatchedFieldsCase.

private void checkMatchedFieldsCase(boolean requireFieldMatch) throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("foo").field("type", "text").field("term_vector", "with_positions_offsets").field("store", true).field("analyzer", "english").startObject("fields").startObject("plain").field("type", "text").field("term_vector", "with_positions_offsets").field("analyzer", "standard").endObject().endObject().endObject().startObject("bar").field("type", "text").field("term_vector", "with_positions_offsets").field("store", true).field("analyzer", "english").startObject("fields").startObject("plain").field("type", "text").field("term_vector", "with_positions_offsets").field("analyzer", "standard").endObject().endObject().endObject().endObject().endObject().endObject()));
    ensureGreen();
    index("test", "type1", "1", "foo", "running with scissors");
    index("test", "type1", "2", "foo", "cat cat junk junk junk junk junk junk junk cats junk junk", "bar", "cat cat junk junk junk junk junk junk junk cats junk junk");
    index("test", "type1", "3", "foo", "weird", "bar", "result");
    refresh();
    Field fooField = new Field("foo").numOfFragments(1).order("score").fragmentSize(25).highlighterType("fvh").requireFieldMatch(requireFieldMatch);
    SearchRequestBuilder req = client().prepareSearch("test").highlighter(new HighlightBuilder().field(fooField));
    // First check highlighting without any matched fields set
    SearchResponse resp = req.setQuery(queryStringQuery("running scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // And that matching a subfield doesn't automatically highlight it
    resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("running with <em>scissors</em>"));
    // Add the subfield to the list of matched fields but don't match it.  Everything should still work
    // like before we added it.
    fooField = new Field("foo").numOfFragments(1).order("score").fragmentSize(25).highlighterType("fvh").requireFieldMatch(requireFieldMatch);
    fooField.matchedFields("foo", "foo.plain");
    req = client().prepareSearch("test").highlighter(new HighlightBuilder().field(fooField));
    resp = req.setQuery(queryStringQuery("running scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // Now make half the matches come from the stored field and half from just a matched field.
    resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // Now remove the stored field from the matched field list.  That should work too.
    fooField = new Field("foo").numOfFragments(1).order("score").fragmentSize(25).highlighterType("fvh").requireFieldMatch(requireFieldMatch);
    fooField.matchedFields("foo.plain");
    req = client().prepareSearch("test").highlighter(new HighlightBuilder().field(fooField));
    resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with scissors"));
    // Now make sure boosted fields don't blow up when matched fields is both the subfield and stored field.
    fooField = new Field("foo").numOfFragments(1).order("score").fragmentSize(25).highlighterType("fvh").requireFieldMatch(requireFieldMatch);
    fooField.matchedFields("foo", "foo.plain");
    req = client().prepareSearch("test").highlighter(new HighlightBuilder().field(fooField));
    resp = req.setQuery(queryStringQuery("foo.plain:running^5 scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // Now just all matches are against the matched field.  This still returns highlighting.
    resp = req.setQuery(queryStringQuery("foo.plain:running foo.plain:scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // And all matched field via the queryString's field parameter, just in case
    resp = req.setQuery(queryStringQuery("running scissors").field("foo.plain")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // Finding the same string two ways is ok too
    resp = req.setQuery(queryStringQuery("run foo.plain:running^5 scissors").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    // But we use the best found score when sorting fragments
    resp = req.setQuery(queryStringQuery("cats foo.plain:cats^5").field("foo")).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
    // which can also be written by searching on the subfield
    resp = req.setQuery(queryStringQuery("cats").field("foo").field("foo.plain", 5)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
    // Speaking of two fields, you can have two fields, only one of which has matchedFields enabled
    QueryBuilder twoFieldsQuery = queryStringQuery("cats").field("foo").field("foo.plain", 5).field("bar").field("bar.plain", 5);
    Field barField = new Field("bar").numOfFragments(1).order("score").fragmentSize(25).highlighterType("fvh").requireFieldMatch(requireFieldMatch);
    resp = req.setQuery(twoFieldsQuery).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
    assertHighlight(resp, 0, "bar", 0, equalTo("<em>cat</em> <em>cat</em> junk junk junk junk"));
    // And you can enable matchedField highlighting on both
    barField.matchedFields("bar", "bar.plain");
    resp = req.setQuery(twoFieldsQuery).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
    assertHighlight(resp, 0, "bar", 0, equalTo("junk junk <em>cats</em> junk junk"));
    // Setting a matchedField that isn't searched/doesn't exist is simply ignored.
    barField.matchedFields("bar", "candy");
    resp = req.setQuery(twoFieldsQuery).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
    assertHighlight(resp, 0, "bar", 0, equalTo("<em>cat</em> <em>cat</em> junk junk junk junk"));
    // If the stored field doesn't have a value it doesn't matter what you match, you get nothing.
    barField.matchedFields("bar", "foo.plain");
    resp = req.setQuery(queryStringQuery("running scissors").field("foo.plain").field("bar")).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar")));
    // If the stored field is found but the matched field isn't then you don't get a result either.
    fooField.matchedFields("bar.plain");
    resp = req.setQuery(queryStringQuery("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("foo")));
    // But if you add the stored field to the list of matched fields then you'll get a result again
    fooField.matchedFields("foo", "bar.plain");
    resp = req.setQuery(queryStringQuery("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
    assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar")));
    // You _can_ highlight fields that aren't subfields of one another.
    resp = req.setQuery(queryStringQuery("weird").field("foo").field("foo.plain").field("bar").field("bar.plain")).highlighter(new HighlightBuilder().field(fooField).field(barField)).get();
    assertHighlight(resp, 0, "foo", 0, equalTo("<em>weird</em>"));
    assertHighlight(resp, 0, "bar", 0, equalTo("<em>resul</em>t"));
    assertFailures(req.setQuery(queryStringQuery("result").field("foo").field("foo.plain").field("bar").field("bar.plain")), RestStatus.INTERNAL_SERVER_ERROR, containsString("IndexOutOfBoundsException"));
}
Also used : Field(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Field) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AbstractQueryBuilder(org.elasticsearch.index.query.AbstractQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with SearchRequestBuilder

use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch by elastic.

the class SearchPreferenceIT method testNodesOnlyRandom.

public void testNodesOnlyRandom() throws Exception {
    assertAcked(prepareCreate("test").setSettings(//this test needs at least a replica to make sure two consecutive searches go to two different copies of the same data
    Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(1, maximumNumberOfReplicas()))));
    ensureGreen();
    client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet();
    refresh();
    final Client client = internalCluster().smartClient();
    SearchRequestBuilder request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(// multiple wildchar  to cover multi-param usecase
    "_only_nodes:*,nodes*");
    assertSearchOnRandomNodes(request);
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference("_only_nodes:*");
    assertSearchOnRandomNodes(request);
    ArrayList<String> allNodeIds = new ArrayList<>();
    ArrayList<String> allNodeNames = new ArrayList<>();
    ArrayList<String> allNodeHosts = new ArrayList<>();
    NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().execute().actionGet();
    for (NodeStats node : nodeStats.getNodes()) {
        allNodeIds.add(node.getNode().getId());
        allNodeNames.add(node.getNode().getName());
        allNodeHosts.add(node.getHostname());
    }
    String node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeIds.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeNames.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeHosts.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeHosts.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    // Mix of valid and invalid nodes
    node_expr = "_only_nodes:*,invalidnode";
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ArrayList(java.util.ArrayList) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Client(org.elasticsearch.client.Client)

Example 5 with SearchRequestBuilder

use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch by elastic.

the class SimpleNestedIT method testSimpleNestedSortingWithNestedFilterMissing.

public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception {
    assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1)).addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("nested1").field("type", "nested").startObject("properties").startObject("field1").field("type", "long").endObject().startObject("field2").field("type", "boolean").endObject().endObject().endObject().endObject().endObject().endObject()));
    ensureGreen();
    client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field1", 1).startArray("nested1").startObject().field("field1", 5).field("field2", true).endObject().startObject().field("field1", 4).field("field2", true).endObject().endArray().endObject()).execute().actionGet();
    client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field1", 2).startArray("nested1").startObject().field("field1", 1).field("field2", true).endObject().startObject().field("field1", 2).field("field2", true).endObject().endArray().endObject()).execute().actionGet();
    // Doc with missing nested docs if nested filter is used
    refresh();
    client().prepareIndex("test", "type1", "3").setSource(jsonBuilder().startObject().field("field1", 3).startArray("nested1").startObject().field("field1", 3).field("field2", false).endObject().startObject().field("field1", 4).field("field2", false).endObject().endArray().endObject()).execute().actionGet();
    refresh();
    SearchRequestBuilder searchRequestBuilder = client().prepareSearch("test").setTypes("type1").setQuery(QueryBuilders.matchAllQuery()).addSort(SortBuilders.fieldSort("nested1.field1").setNestedPath("nested1").setNestedFilter(termQuery("nested1.field2", true)).missing(10).order(SortOrder.ASC));
    if (randomBoolean()) {
        searchRequestBuilder.setScroll("10m");
    }
    SearchResponse searchResponse = searchRequestBuilder.get();
    assertHitCount(searchResponse, 3);
    assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("2"));
    assertThat(searchResponse.getHits().getHits()[0].getSortValues()[0].toString(), equalTo("1"));
    assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("1"));
    assertThat(searchResponse.getHits().getHits()[1].getSortValues()[0].toString(), equalTo("4"));
    assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("3"));
    assertThat(searchResponse.getHits().getHits()[2].getSortValues()[0].toString(), equalTo("10"));
    searchRequestBuilder = client().prepareSearch("test").setTypes("type1").setQuery(QueryBuilders.matchAllQuery()).addSort(SortBuilders.fieldSort("nested1.field1").setNestedPath("nested1").setNestedFilter(termQuery("nested1.field2", true)).missing(10).order(SortOrder.DESC));
    if (randomBoolean()) {
        searchRequestBuilder.setScroll("10m");
    }
    searchResponse = searchRequestBuilder.get();
    assertHitCount(searchResponse, 3);
    assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("3"));
    assertThat(searchResponse.getHits().getHits()[0].getSortValues()[0].toString(), equalTo("10"));
    assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("1"));
    assertThat(searchResponse.getHits().getHits()[1].getSortValues()[0].toString(), equalTo("5"));
    assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("2"));
    assertThat(searchResponse.getHits().getHits()[2].getSortValues()[0].toString(), equalTo("2"));
    client().prepareClearScroll().addScrollId("_all").get();
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)110 SearchResponse (org.elasticsearch.action.search.SearchResponse)66 SearchHit (org.elasticsearch.search.SearchHit)23 SearchHits (org.elasticsearch.search.SearchHits)18 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)17 ArrayList (java.util.ArrayList)14 Client (org.elasticsearch.client.Client)13 HashMap (java.util.HashMap)12 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)12 Test (org.junit.Test)12 SearchRequest (org.elasticsearch.action.search.SearchRequest)11 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)10 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)9 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)9 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)9 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)8 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)8 Map (java.util.Map)7 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)7 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)7