Java 类org.elasticsearch.action.search.SearchPhaseExecutionException 实例源码

项目:elasticsearch_my    文件:ChildQuerySearchIT.java   
private SearchResponse minMaxQuery(ScoreMode scoreMode, int minChildren, Integer maxChildren) throws SearchPhaseExecutionException {
    HasChildQueryBuilder hasChildQuery = hasChildQuery(
            "child",
            QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two")),
                    new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))
                    }).boostMode(CombineFunction.REPLACE).scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM), scoreMode)
            .minMaxChildren(minChildren, maxChildren != null ? maxChildren : HasChildQueryBuilder.DEFAULT_MAX_CHILDREN);

    return client()
            .prepareSearch("test")
            .setQuery(hasChildQuery)
            .addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
}
项目:elasticsearch_my    文件:PercolatorQuerySearchIT.java   
public void testPercolatorQueryExistingDocumentSourceDisabled() throws Exception {
    createIndex("test", client().admin().indices().prepareCreate("test")
        .addMapping("type", "_source", "enabled=false", "field1", "type=keyword")
        .addMapping("queries", "query", "type=percolator")
    );

    client().prepareIndex("test", "queries", "1")
        .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
        .get();

    client().prepareIndex("test", "type", "1").setSource("{}", XContentType.JSON).get();
    client().admin().indices().prepareRefresh().get();

    logger.info("percolating empty doc with source disabled");
    Throwable e = expectThrows(SearchPhaseExecutionException.class, () -> {
        client().prepareSearch()
            .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "1", null, null, null))
            .get();
    }).getRootCause();
    assertThat(e, instanceOf(IllegalArgumentException.class));
    assertThat(e.getMessage(), containsString("source disabled"));
}
项目:elasticsearch_my    文件:IndexLookupIT.java   
private void checkExceptions(Script script) {
    try {
        SearchResponse sr = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).addScriptField("tvtest", script)
                .execute().actionGet();
        assertThat(sr.getHits().getHits().length, equalTo(0));
        ShardSearchFailure[] shardFails = sr.getShardFailures();
        for (ShardSearchFailure fail : shardFails) {
            assertThat(fail.reason().indexOf("Cannot iterate twice! If you want to iterate more that once, add _CACHE explicitly."),
                    Matchers.greaterThan(-1));
        }
    } catch (SearchPhaseExecutionException ex) {
        assertThat(
                "got " + ex.toString(),
                ex.toString().indexOf("Cannot iterate twice! If you want to iterate more that once, add _CACHE explicitly."),
                Matchers.greaterThan(-1));
    }
}
项目:elasticsearch_my    文件:PercentilesBucketIT.java   
public void testBadPercents() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client().prepareSearch("idx")
                .addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                .addAggregation(percentilesBucket("percentiles_bucket", "terms>sum")
                        .percents(badPercents)).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
项目:elasticsearch_my    文件:MovAvgIT.java   
public void testBadParent() {
    try {
        client()
                .prepareSearch("idx").setTypes("type")
                .addAggregation(
                        range("histo").field(INTERVAL_FIELD).addRange(0, 10)
                                .subAggregation(randomMetric("the_metric", VALUE_FIELD))
                                .subAggregation(movingAvg("movavg_counts", "the_metric")
                                        .window(windowSize)
                                        .modelBuilder(new SimpleModel.SimpleModelBuilder())
                                        .gapPolicy(gapPolicy))
                ).execute().actionGet();
        fail("MovingAvg should not accept non-histogram as parent");

    } catch (SearchPhaseExecutionException exception) {
        // All good
    }
}
项目:elasticsearch_my    文件:MovAvgIT.java   
public void testHoltWintersNotEnoughData() {
    try {
        SearchResponse response = client()
                .prepareSearch("idx").setTypes("type")
                .addAggregation(
                        histogram("histo").field(INTERVAL_FIELD).interval(interval)
                                .extendedBounds(0L, (long) (interval * (numBuckets - 1)))
                                .subAggregation(metric)
                                .subAggregation(movingAvg("movavg_counts", "_count")
                                        .window(10)
                                        .modelBuilder(new HoltWintersModel.HoltWintersModelBuilder()
                                                .alpha(alpha).beta(beta).gamma(gamma).period(20).seasonalityType(seasonalityType))
                                        .gapPolicy(gapPolicy))
                                .subAggregation(movingAvg("movavg_values", "the_metric")
                                        .window(windowSize)
                                        .modelBuilder(new HoltWintersModel.HoltWintersModelBuilder()
                                                .alpha(alpha).beta(beta).gamma(gamma).period(20).seasonalityType(seasonalityType))
                                        .gapPolicy(gapPolicy))
                ).execute().actionGet();
    } catch (SearchPhaseExecutionException e) {
        // All good
    }

}
项目:elasticsearch_my    文件:MovAvgIT.java   
public void testBadModelParams() {
    try {
        SearchResponse response = client()
                .prepareSearch("idx").setTypes("type")
                .addAggregation(
                        histogram("histo").field(INTERVAL_FIELD).interval(interval)
                                .extendedBounds(0L, (long) (interval * (numBuckets - 1)))
                                .subAggregation(metric)
                                .subAggregation(movingAvg("movavg_counts", "_count")
                                        .window(10)
                                        .modelBuilder(randomModelBuilder(100))
                                        .gapPolicy(gapPolicy))
                ).execute().actionGet();
    } catch (SearchPhaseExecutionException e) {
        // All good
    }

}
项目:elasticsearch_my    文件:AdjacencyMatrixIT.java   
public void testTooLargeMatrix() throws Exception{

        // Create more filters than is permitted by index settings.
        MapBuilder filtersMap = new MapBuilder();
        for (int i = 0; i <= MAX_NUM_FILTERS; i++) {
            filtersMap.add("tag" + i, termQuery("tag", "tag" + i));
        }

        try {
            client().prepareSearch("idx")
                .addAggregation(adjacencyMatrix("tags", "\t", filtersMap))
                .execute().actionGet();
            fail("SearchPhaseExecutionException should have been thrown");
        } catch (SearchPhaseExecutionException ex) {
            assertThat(ex.getCause().getMessage(), containsString("Number of filters is too large"));
        }
    }
项目:elasticsearch_my    文件:ReverseNestedIT.java   
public void testReverseNestedAggWithoutNestedAgg() {
    try {
        client().prepareSearch("idx")
                .addAggregation(terms("field2").field("nested1.nested2.field2")
                        .collectMode(randomFrom(SubAggCollectionMode.values()))
                                .subAggregation(
                                        reverseNested("nested1_to_field1")
                                                .subAggregation(
                                                        terms("field1").field("nested1.field1")
                                                        .collectMode(randomFrom(SubAggCollectionMode.values()))
                                                )
                                )
                ).get();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
项目:elasticsearch_my    文件:SearchServiceTests.java   
public void testCloseSearchContextOnRewriteException() {
    createIndex("index");
    client().prepareIndex("index", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();

    SearchService service = getInstanceFromNode(SearchService.class);
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService indexService = indicesService.indexServiceSafe(resolveIndex("index"));
    IndexShard indexShard = indexService.getShard(0);

    final int activeContexts = service.getActiveContexts();
    final int activeRefs = indexShard.store().refCount();
    expectThrows(SearchPhaseExecutionException.class, () ->
            client().prepareSearch("index").setQuery(new FailOnRewriteQueryBuilder()).get());
    assertEquals(activeContexts, service.getActiveContexts());
    assertEquals(activeRefs, indexShard.store().refCount());
}
项目:elasticsearch_my    文件:DecayFunctionScoreIT.java   
public void testExceptionThrownIfScaleLE0() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num1").field("type", "date").endObject().endObject().endObject().endObject()));
    client().index(
            indexRequest("test").type("type1").id("1")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("2")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-28").endObject())).actionGet();
    refresh();

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num1", "2013-05-28", "-1d")))));
    try {
        response.actionGet();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
项目:elasticsearch_my    文件:DecayFunctionScoreIT.java   
public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type",
            jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num").field("type", "text").endObject().endObject().endObject().endObject()));
    client().index(
            indexRequest("test").type("type").source(
                    jsonBuilder().startObject().field("test", "value").field("num", Integer.toString(1)).endObject())).actionGet();
    refresh();
    // so, we indexed a string field, but now we try to score a num field
    ActionFuture<SearchResponse> response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
            .source(searchSource().query(functionScoreQuery(termQuery("test", "value"), linearDecayFunction("num", 1.0, 0.5))
                    .scoreMode(ScoreMode.MULTIPLY))));
    try {
        response.actionGet();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
项目:elasticsearch_my    文件:SearchQueryIT.java   
public void testDateRangeInQueryString() {
    //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", "future", "type=date"
    ));

    String aMonthAgo = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).minusMonths(1));
    String aMonthFromNow = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).plusMonths(1));
    client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
    refresh();

    SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
    assertHitCount(searchResponse, 1L);

    searchResponse = client().prepareSearch().setQuery(queryStringQuery("future:[now/d TO now+2M/d]")).get();
    assertHitCount(searchResponse, 1L);

    SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch()
            .setQuery(queryStringQuery("future:[now/D TO now+2M/d]").lenient(false)).get());
    assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
    assertThat(e.toString(), containsString("unit [D] not supported for date math"));
}
项目:elasticsearch_my    文件:SearchQueryIT.java   
public void testMatchQueryNumeric() throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", "long", "type=long", "double", "type=double"));

    indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("long", 1L, "double", 1.0d),
            client().prepareIndex("test", "type1", "2").setSource("long", 2L, "double", 2.0d),
            client().prepareIndex("test", "type1", "3").setSource("long", 3L, "double", 3.0d));

    SearchResponse searchResponse = client().prepareSearch().setQuery(matchQuery("long", "1")).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("1"));

    searchResponse = client().prepareSearch().setQuery(matchQuery("double", "2")).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("2"));
    expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setQuery(matchQuery("double", "2 3 4")).get());
}
项目:elasticsearch_my    文件:CompletionSuggestSearchIT.java   
public void testThatSortingOnCompletionFieldReturnsUsefulException() throws Exception {
    createIndexAndMapping(completionMappingBuilder);

    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
            .startObject().startObject(FIELD)
            .startArray("input").value("Nirvana").endArray()
            .endObject().endObject()
    ).get();

    refresh();
    try {
        client().prepareSearch(INDEX).setTypes(TYPE).addSort(new FieldSortBuilder(FIELD)).execute().actionGet();
        fail("Expected an exception due to trying to sort on completion field, but did not happen");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.status().getStatus(), is(400));
        assertThat(e.toString(), containsString("Fielddata is not supported on field [" + FIELD + "] of type [completion]"));
    }
}
项目:elasticsearch_my    文件:CompletionSuggestSearchIT.java   
public void testIssue5930() throws IOException {
    assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject()
            .startObject(TYPE).startObject("properties")
            .startObject(FIELD)
            .field("type", "completion")
            .endObject()
            .endObject().endObject()
            .endObject()).get());
    String string = "foo bar";
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
                    .startObject()
                    .field(FIELD, string)
                    .endObject()
    ).setRefreshPolicy(IMMEDIATE).get();

    try {
        client().prepareSearch(INDEX).addAggregation(AggregationBuilders.terms("suggest_agg").field(FIELD)
                .collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
        // Exception must be thrown
        assertFalse(true);
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString(), containsString("Fielddata is not supported on field [" + FIELD + "] of type [completion]"));
    }
}
项目:elasticsearch_my    文件:SearchSliceIT.java   
public void testInvalidFields() throws Exception {
    setupIndex(false);
    SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class,
        () -> client().prepareSearch("test")
            .setQuery(matchAllQuery())
            .setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
            .slice(new SliceBuilder("invalid_random_int", 0, 10))
            .get());
    Throwable rootCause = findRootCause(exc);
    assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
    assertThat(rootCause.getMessage(),
        startsWith("cannot load numeric doc values"));

    exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test")
        .setQuery(matchAllQuery())
        .setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
        .slice(new SliceBuilder("invalid_random_kw", 0, 10))
        .get());
    rootCause = findRootCause(exc);
    assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
    assertThat(rootCause.getMessage(),
        startsWith("cannot load numeric doc values"));
}
项目:elasticsearch_my    文件:TransportTwoNodesSearchIT.java   
public void testFailedSearchWithWrongQuery() throws Exception {
   prepareData();

   NumShards test = getNumShards("test");

   logger.info("Start Testing failed search with wrong query");
   try {
       SearchResponse searchResponse = client().search(
               searchRequest("test").source(new SearchSourceBuilder().query(new MatchQueryBuilder("foo", "biz")))).actionGet();
       assertThat(searchResponse.getTotalShards(), equalTo(test.numPrimaries));
       assertThat(searchResponse.getSuccessfulShards(), equalTo(0));
       assertThat(searchResponse.getFailedShards(), equalTo(test.numPrimaries));
       fail("search should fail");
   } catch (ElasticsearchException e) {
       assertThat(e.unwrapCause(), instanceOf(SearchPhaseExecutionException.class));
       // all is well
   }
   logger.info("Done Testing failed search");
}
项目:elasticsearch_my    文件:ExceptionSerializationTests.java   
public void testSearchPhaseExecutionException() throws IOException {
    ShardSearchFailure[] empty = new ShardSearchFailure[0];
    SearchPhaseExecutionException ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), empty));
    assertEquals("boom", ex.getPhaseName());
    assertEquals("baam", ex.getMessage());
    assertTrue(ex.getCause() instanceof NullPointerException);
    assertEquals(empty.length, ex.shardFailures().length);
    ShardSearchFailure[] one = new ShardSearchFailure[]{
            new ShardSearchFailure(new IllegalArgumentException("nono!"))
    };

    ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), one));
    assertEquals("boom", ex.getPhaseName());
    assertEquals("baam", ex.getMessage());
    assertTrue(ex.getCause() instanceof NullPointerException);
    assertEquals(one.length, ex.shardFailures().length);
    assertTrue(ex.shardFailures()[0].getCause() instanceof IllegalArgumentException);
}
项目:gchange-pod    文件:AbstractCommentDaoImpl.java   
@Override
public long countReplies(String id) {

    // Prepare count request
    SearchRequestBuilder searchRequest = client
            .prepareSearch(getIndex())
            .setTypes(getType())
            .setFetchSource(false)
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setSize(0);

    // Query = filter on reference
    TermQueryBuilder query = QueryBuilders.termQuery(RecordComment.PROPERTY_REPLY_TO_JSON, id);
    searchRequest.setQuery(query);

    // Execute query
    try {
        SearchResponse response = searchRequest.execute().actionGet();
        return response.getHits().getTotalHits();
    }
    catch(SearchPhaseExecutionException e) {
        // Failed or no item on index
        logger.error(String.format("Error while counting comment replies: %s", e.getMessage()), e);
    }
    return 1;
}
项目:elasticsearch-multiple-metric-aggregation    文件:MultipleMetricParserTest.java   
@Test(expected=SearchPhaseExecutionException.class)
public void assertMissingFieldOrScript() throws Exception {
    String indexName = "index0";
    int numberOfShards = 1;

    createIndex(numberOfShards, indexName);

    client().prepareSearch("index0").setAggregations(JsonXContent.contentBuilder()
        .startObject()
            .startObject("metrics")
                .startObject("value1")
                .startObject("sum")
                    .field("nofield", "field")
                    .endObject()
                .endObject()
            .endObject()
        .endObject()).execute().actionGet();
}
项目:elasticsearch-multiple-metric-aggregation    文件:MultipleMetricParserTest.java   
@Test(expected=SearchPhaseExecutionException.class)
public void assertMissingOperator() throws Exception {
    String indexName = "index1";
    int numberOfShards = 1;

    createIndex(numberOfShards, indexName);

    client().prepareSearch("index1").setAggregations(JsonXContent.contentBuilder()
        .startObject()
            .startObject("metrics")
                .startObject("value1")
                .startObject("bad-aggregator")
                .field("field", "a")
            .endObject()
                .endObject()
            .endObject()
        .endObject()).execute().actionGet();
}
项目:spacedog-server    文件:JsonPayload.java   
public static int status(Throwable t) {

        if (t instanceof IllegalArgumentException)
            return HttpStatus.BAD_REQUEST;
        if (t instanceof AmazonServiceException)
            return ((AmazonServiceException) t).getStatusCode();
        if (t instanceof SpaceException)
            return ((SpaceException) t).httpStatus();
        // elastic returns 500 when result window is too large
        // let's return 400 instead
        if (t instanceof SearchPhaseExecutionException)
            if (t.toString().contains("from + size must be less"))
                return HttpStatus.BAD_REQUEST;
        if (t instanceof ElasticsearchException)
            return ((ElasticsearchException) t).status().getStatus();
        if (t.getCause() != null)
            return status(t.getCause());

        return HttpStatus.INTERNAL_SERVER_ERROR;
    }
项目:searchisko    文件:SearchPhaseExecutionExceptionMapper.java   
@Override
    public Response toResponse(SearchPhaseExecutionException exception) {
        if (log.isLoggable(Level.WARNING)) {
            log.log(Level.WARNING, "Exception {0} occurred. Message: {1}",
                    new Object[] { exception.getClass().getName(), exception.getMessage() });
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE, "Exception trace.", exception);
            }
        }
        final Response.ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
        // TODO: We need to figure out which project stage we're in
        final StringBuilder exceptionMessage = new StringBuilder("An error occurred during your search.");
//        if (!production) {
            exceptionMessage.append(exception.getMessage());
//        } else {
//            response.entity("An error occurred during your search.");
//        }
        response.entity(exceptionMessage.toString());
        return response.build();
    }
项目:MyDMAM    文件:ContainerOperations.java   
/**
 * Delete orphan (w/o pathindex) metadatas elements
 */
public static void purge_orphan_metadatas(boolean let_clean_empty_and_removed_storages) throws Exception {
    try {
        ElastisearchCrawlerReader reader = Elasticsearch.createCrawlerReader();
        reader.setIndices(ES_INDEX);
        reader.setQuery(QueryBuilders.matchAllQuery());

        ElasticsearchBulkOperation es_bulk = Elasticsearch.prepareBulk();

        HitPurge hit_purge = new HitPurge(es_bulk, let_clean_empty_and_removed_storages);
        reader.allReader(hit_purge);
        es_bulk.terminateBulk();

        Loggers.Metadata.info("Start cleaning rendered elements");

        RenderedFile.purge_orphan_metadatas_files();

    } catch (IndexMissingException ime) {
        Loggers.Metadata.warn("Can't purge orphan metadatas: " + ES_INDEX + " index is not present", ime);
    } catch (SearchPhaseExecutionException e) {
        Loggers.Metadata.warn("Can't purge orphan metadatas", e);
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testInvalidDateMethodCall() throws Exception {
    ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "double", "type=double"));
    ensureGreen("test");
    indexRandom(true, client().prepareIndex("test", "doc", "1").setSource("double", "178000000.0"));
    try {
        buildRequest("doc['double'].getYear()").get();
        fail();
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained IllegalArgumentException",
                e.toString().contains("IllegalArgumentException"), equalTo(true));
        assertThat(e.toString() + "should have contained does not exist for numeric field",
                e.toString().contains("does not exist for numeric field"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testMissingField() throws Exception {
    createIndex("test");
    ensureGreen("test");
    client().prepareIndex("test", "doc", "1").setSource("x", 4).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("doc['bogus']").get();
        fail("Expected missing field to cause failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained missing field error",
                e.toString().contains("does not exist in mappings"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testCompileFailure() {
    client().prepareIndex("test", "doc", "1").setSource("x", 1).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("garbage%@#%@").get();
        fail("Expected expression compilation failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained compilation failure",
                e.toString().contains("compile error"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testNonNumericParam() {
    client().prepareIndex("test", "doc", "1").setSource("x", 1).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("a", "a", "astring").get();
        fail("Expected string parameter to cause failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained non-numeric parameter error",
                e.toString().contains("must be a numeric type"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testNonNumericField() {
    client().prepareIndex("test", "doc", "1").setSource("text", "this is not a number").setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("doc['text.keyword']").get();
        fail("Expected text field to cause execution failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained non-numeric field error",
                e.toString().contains("must be numeric"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testInvalidGlobalVariable() {
    client().prepareIndex("test", "doc", "1").setSource("foo", 5).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("bogus").get();
        fail("Expected bogus variable to cause execution failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained unknown variable error",
                e.toString().contains("Unknown variable"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testDocWithoutField() {
    client().prepareIndex("test", "doc", "1").setSource("foo", 5).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("doc").get();
        fail("Expected doc variable without field to cause execution failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained a missing specific field error",
                e.toString().contains("must be used with a specific field"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testInvalidFieldMember() {
    client().prepareIndex("test", "doc", "1").setSource("foo", 5).setRefreshPolicy(IMMEDIATE).get();
    try {
        buildRequest("doc['foo'].bogus").get();
        fail("Expected bogus field member to cause execution failure");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString() + "should have contained ScriptException",
                e.toString().contains("ScriptException"), equalTo(true));
        assertThat(e.toString() + "should have contained member variable [bogus] does not exist",
                e.toString().contains("Member variable [bogus] does not exist"), equalTo(true));
    }
}
项目:elasticsearch_my    文件:MoreExpressionTests.java   
public void testStringSpecialValueVariable() throws Exception {
    // i.e. expression script for term aggregations, which is not allowed
    assertAcked(client().admin().indices().prepareCreate("test")
            .addMapping("doc", "text", "type=keyword").get());
    ensureGreen("test");
    indexRandom(true,
            client().prepareIndex("test", "doc", "1").setSource("text", "hello"),
            client().prepareIndex("test", "doc", "2").setSource("text", "goodbye"),
            client().prepareIndex("test", "doc", "3").setSource("text", "hello"));

    SearchRequestBuilder req = client().prepareSearch().setIndices("test");
    req.setQuery(QueryBuilders.matchAllQuery())
            .addAggregation(
                    AggregationBuilders.terms("term_agg").field("text")
                            .script(
                                new Script(ScriptType.INLINE, ExpressionScriptEngineService.NAME, "_value", Collections.emptyMap())));

    String message;
    try {
        // shards that don't have docs with the "text" field will not fail,
        // so we may or may not get a total failure
        SearchResponse rsp = req.get();
        assertThat(rsp.getShardFailures().length, greaterThan(0)); // at least the shards containing the docs should have failed
        message = rsp.getShardFailures()[0].reason();
    } catch (SearchPhaseExecutionException e) {
        message = e.toString();
    }
    assertThat(message + "should have contained ScriptException",
            message.contains("ScriptException"), equalTo(true));
    assertThat(message + "should have contained text variable error",
            message.contains("text variable"), equalTo(true));
}
项目:elasticsearch_my    文件:TopHitsIT.java   
public void testInvalidSortField() throws Exception {
    try {
        client().prepareSearch("idx").setTypes("type")
                .addAggregation(terms("terms")
                                .executionHint(randomExecutionHint())
                                .field(TERMS_AGGS_FIELD)
                                .subAggregation(
                                        topHits("hits").sort(SortBuilders.fieldSort("xyz").order(SortOrder.DESC))
                                )
                ).get();
        fail();
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString(), containsString("No mapping found for [xyz] in order to sort on"));
    }
}
项目:elasticsearch_my    文件:DerivativeIT.java   
public void testSingleValueAggDerivative_invalidPath() throws Exception {
    try {
        client().prepareSearch("idx")
                .addAggregation(
                        histogram("histo")
                                .field(SINGLE_VALUED_FIELD_NAME)
                                .interval(interval)
                                .subAggregation(
                                        filters("filters", QueryBuilders.termQuery("tag", "foo")).subAggregation(
                                                sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(derivative("deriv", "filters>get>sum"))).execute().actionGet();
        fail("Expected an Exception but didn't get one");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
项目:elasticsearch_my    文件:PercentilesBucketIT.java   
public void testBadPercents_asSubAgg() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client()
            .prepareSearch("idx")
            .addAggregation(
                    terms("terms")
                            .field("tag")
                            .order(Terms.Order.term(true))
                            .subAggregation(
                                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                            .extendedBounds(minRandomValue, maxRandomValue))
                            .subAggregation(percentilesBucket("percentiles_bucket", "histo>_count")
                                    .percents(badPercents))).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
项目:elasticsearch_my    文件:ExtendedStatsBucketIT.java   
public void testBadSigmaAsSubAgg() throws Exception {
    try {
        SearchResponse response = client()
                .prepareSearch("idx")
                .addAggregation(
                        terms("terms")
                                .field("tag")
                                .order(Order.term(true))
                                .subAggregation(
                                        histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                                .extendedBounds(minRandomValue, maxRandomValue)
                                                .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(extendedStatsBucket("extended_stats_bucket", "histo>sum")
                                        .sigma(-1.0))).execute().actionGet();
        fail("Illegal sigma was provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
项目:elasticsearch_my    文件:MovAvgIT.java   
/**
 * These models are all minimizable, so they should not throw exceptions
 */
public void testCheckIfTunableCanBeMinimized() {
    MovAvgModelBuilder[] builders = new MovAvgModelBuilder[]{
            new EwmaModel.EWMAModelBuilder(),
            new HoltLinearModel.HoltLinearModelBuilder(),
            new HoltWintersModel.HoltWintersModelBuilder()
    };

    for (MovAvgModelBuilder builder : builders) {
        try {
            client()
                    .prepareSearch("idx").setTypes("type")
                    .addAggregation(
                            histogram("histo").field(INTERVAL_FIELD).interval(interval)
                                    .extendedBounds(0L, (long) (interval * (numBuckets - 1)))
                                    .subAggregation(metric)
                                    .subAggregation(movingAvg("movavg_counts", "_count")
                                            .window(numBuckets)
                                            .modelBuilder(builder)
                                            .gapPolicy(gapPolicy)
                                            .minimize(true))
                    ).execute().actionGet();
        } catch (SearchPhaseExecutionException e) {
            fail("Model [" + builder.toString() + "] can be minimized, but an exception was thrown");
        }
    }
}
项目:elasticsearch_my    文件:StringTermsIT.java   
public void testSingleValuedFieldOrderedByIllegalAgg() throws Exception {
    boolean asc = true;
    try {
        client()
            .prepareSearch("idx")
            .setTypes("type")
            .addAggregation(
                    terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME)
                            .collectMode(randomFrom(SubAggCollectionMode.values()))
                            .order(Terms.Order.aggregation("inner_terms>avg", asc))
                            .subAggregation(terms("inner_terms").field(MULTI_VALUED_FIELD_NAME).subAggregation(avg("avg").field("i"))))
            .execute().actionGet();
        fail("Expected an exception");
    } catch (SearchPhaseExecutionException e) {
        ElasticsearchException[] rootCauses = e.guessRootCauses();
        if (rootCauses.length == 1) {
            ElasticsearchException rootCause = rootCauses[0];
            if (rootCause instanceof AggregationExecutionException) {
                AggregationExecutionException aggException = (AggregationExecutionException) rootCause;
                assertThat(aggException.getMessage(), Matchers.startsWith("Invalid terms aggregation order path"));
            } else {
                throw e;
            }
        } else {
            throw e;
        }
    }
}