Java Code Examples for org.elasticsearch.client.Request#addParameter()

The following examples show how to use org.elasticsearch.client.Request#addParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobIT.java    From zentity with Apache License 2.0 5 votes vote down vote up
public void testJobExplanation() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a";
        Request postResolution = new Request("POST", endpoint);
        postResolution.addParameter("_attributes", "false");
        postResolution.addParameter("_explanation", "true");
        postResolution.addParameter("_source", "false");
        postResolution.addParameter("max_hops", "1");
        postResolution.addParameter("max_docs_per_query", "2");
        postResolution.setEntity(TEST_PAYLOAD_JOB_EXPLANATION);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
        assertEquals(json.get("hits").get("total").asInt(), 3);
        Set<String> docsExpected = new TreeSet<>();
        docsExpected.add("a0,0");
        docsExpected.add("a1,1");
        docsExpected.add("a2,1");
        assertEquals(docsExpected, getActual(json));
        for (JsonNode doc : json.get("hits").get("hits")) {
            String expected = "";
            switch (doc.get("_id").asText()) {
                case "a0":
                    expected = "{\"resolvers\":{\"resolver_a\":{\"attributes\":[\"attribute_a\"]},\"resolver_type_date_a\":{\"attributes\":[\"attribute_a\",\"attribute_type_date\"]}},\"matches\":[{\"attribute\":\"attribute_a\",\"target_field\":\"field_a.clean\",\"target_value\":\"a_00\",\"input_value\":\"a_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_a\",\"target_field\":\"field_a.keyword\",\"target_value\":\"a_00\",\"input_value\":\"a_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"1999-12-31T23:59:57.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}}]}";
                    break;
                case "a1":
                    expected = "{\"resolvers\":{\"resolver_c\":{\"attributes\":[\"attribute_d\"]},\"resolver_type_date_c\":{\"attributes\":[\"attribute_d\",\"attribute_type_date\"]}},\"matches\":[{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.clean\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.keyword\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"1999-12-31T23:59:59.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}}]}";
                    break;
                case "a2":
                    expected = "{\"resolvers\":{\"resolver_c\":{\"attributes\":[\"attribute_d\"]},\"resolver_object\":{\"attributes\":[\"attribute_object\"]},\"resolver_type_boolean\":{\"attributes\":[\"attribute_type_boolean\"]},\"resolver_type_date_c\":{\"attributes\":[\"attribute_d\",\"attribute_type_date\"]},\"resolver_type_double\":{\"attributes\":[\"attribute_type_double\"]},\"resolver_type_float\":{\"attributes\":[\"attribute_type_float\"]},\"resolver_type_integer\":{\"attributes\":[\"attribute_type_integer\"]},\"resolver_type_long\":{\"attributes\":[\"attribute_type_long\"]},\"resolver_type_string\":{\"attributes\":[\"attribute_type_string\"]}},\"matches\":[{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.clean\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.keyword\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_object\",\"target_field\":\"object.a.b.c.keyword\",\"target_value\":\"a\",\"input_value\":\"a\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_boolean\",\"target_field\":\"type_boolean\",\"target_value\":true,\"input_value\":true,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"2000-01-01T00:00:00.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}},{\"attribute\":\"attribute_type_double\",\"target_field\":\"type_double\",\"target_value\":3.141592653589793,\"input_value\":3.141592653589793,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_float\",\"target_field\":\"type_float\",\"target_value\":1.0,\"input_value\":1.0,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_integer\",\"target_field\":\"type_integer\",\"target_value\":1,\"input_value\":1,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_long\",\"target_field\":\"type_long\",\"target_value\":922337203685477,\"input_value\":922337203685477,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_string\",\"target_field\":\"type_string\",\"target_value\":\"a\",\"input_value\":\"a\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}}]}";
                    break;
            }
            assertEquals(expected, Json.MAPPER.writeValueAsString(doc.get("_explanation")));
        }
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 2
Source File: JobIT.java    From zentity with Apache License 2.0 5 votes vote down vote up
public void testJobExplanationTerms() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a";
        Request postResolution = new Request("POST", endpoint);
        postResolution.addParameter("_attributes", "false");
        postResolution.addParameter("_explanation", "true");
        postResolution.addParameter("_source", "false");
        postResolution.addParameter("max_hops", "1");
        postResolution.addParameter("max_docs_per_query", "2");
        postResolution.setEntity(TEST_PAYLOAD_JOB_EXPLANATION_TERMS);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
        assertEquals(json.get("hits").get("total").asInt(), 3);
        Set<String> docsExpected = new TreeSet<>();
        docsExpected.add("a0,0");
        docsExpected.add("a1,1");
        docsExpected.add("a2,1");
        assertEquals(docsExpected, getActual(json));
        for (JsonNode doc : json.get("hits").get("hits")) {
            String expected = "";
            switch (doc.get("_id").asText()) {
                case "a0":
                    expected = "{\"resolvers\":{\"resolver_a\":{\"attributes\":[\"attribute_a\"]},\"resolver_type_date_a\":{\"attributes\":[\"attribute_a\",\"attribute_type_date\"]}},\"matches\":[{\"attribute\":\"attribute_a\",\"target_field\":\"field_a.clean\",\"target_value\":\"a_00\",\"input_value\":\"a_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_a\",\"target_field\":\"field_a.keyword\",\"target_value\":\"a_00\",\"input_value\":\"a_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"1999-12-31T23:59:57.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}}]}";
                    break;
                case "a1":
                    expected = "{\"resolvers\":{\"resolver_c\":{\"attributes\":[\"attribute_d\"]},\"resolver_type_date_c\":{\"attributes\":[\"attribute_d\",\"attribute_type_date\"]}},\"matches\":[{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.clean\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.keyword\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"1999-12-31T23:59:59.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}}]}";
                    break;
                case "a2":
                    expected = "{\"resolvers\":{\"resolver_c\":{\"attributes\":[\"attribute_d\"]},\"resolver_object\":{\"attributes\":[\"attribute_object\"]},\"resolver_type_boolean\":{\"attributes\":[\"attribute_type_boolean\"]},\"resolver_type_date_c\":{\"attributes\":[\"attribute_d\",\"attribute_type_date\"]},\"resolver_type_double\":{\"attributes\":[\"attribute_type_double\"]},\"resolver_type_float\":{\"attributes\":[\"attribute_type_float\"]},\"resolver_type_integer\":{\"attributes\":[\"attribute_type_integer\"]},\"resolver_type_long\":{\"attributes\":[\"attribute_type_long\"]},\"resolver_type_string\":{\"attributes\":[\"attribute_type_string\"]}},\"matches\":[{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.clean\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_a\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_d\",\"target_field\":\"field_d.keyword\",\"target_value\":\"d_00\",\"input_value\":\"d_00\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_object\",\"target_field\":\"object.a.b.c.keyword\",\"target_value\":\"a\",\"input_value\":\"a\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_boolean\",\"target_field\":\"type_boolean\",\"target_value\":true,\"input_value\":true,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_date\",\"target_field\":\"type_date\",\"target_value\":\"2000-01-01T00:00:00.0000\",\"input_value\":\"1999-12-31T23:59:57.0000\",\"input_matcher\":\"matcher_c\",\"input_matcher_params\":{\"format\":\"yyyy-MM-dd'T'HH:mm:ss.0000\",\"window\":\"1d\"}},{\"attribute\":\"attribute_type_double\",\"target_field\":\"type_double\",\"target_value\":3.141592653589793,\"input_value\":3.141592653589793,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_float\",\"target_field\":\"type_float\",\"target_value\":1.0,\"input_value\":1.0,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_integer\",\"target_field\":\"type_integer\",\"target_value\":1,\"input_value\":1,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_long\",\"target_field\":\"type_long\",\"target_value\":922337203685477,\"input_value\":922337203685477,\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}},{\"attribute\":\"attribute_type_string\",\"target_field\":\"type_string\",\"target_value\":\"a\",\"input_value\":\"a\",\"input_matcher\":\"matcher_b\",\"input_matcher_params\":{}}]}";
                    break;
            }
            assertEquals(expected, Json.MAPPER.writeValueAsString(doc.get("_explanation")));
        }
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 3
Source File: JobIT.java    From zentity with Apache License 2.0 5 votes vote down vote up
public void testJobMaxHopsAndDocs() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a";
        Request postResolution = new Request("POST", endpoint);
        postResolution.addParameter("max_hops", "2");
        postResolution.addParameter("max_docs_per_query", "2");
        postResolution.setEntity(TEST_PAYLOAD_JOB_MAX_HOPS_AND_DOCS);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
        assertEquals(json.get("hits").get("total").asInt(), 20);
        Set<String> docsExpected = new TreeSet<>();
        docsExpected.add("a0,0");
        docsExpected.add("a1,0");
        docsExpected.add("b0,0");
        docsExpected.add("b1,0");
        docsExpected.add("c0,0");
        docsExpected.add("c1,0");
        docsExpected.add("d0,0");
        docsExpected.add("d1,0");
        docsExpected.add("a2,1");
        docsExpected.add("b2,1");
        docsExpected.add("c2,1");
        docsExpected.add("d2,1");
        docsExpected.add("a3,2");
        docsExpected.add("a4,2");
        docsExpected.add("b3,2");
        docsExpected.add("b4,2");
        docsExpected.add("c3,2");
        docsExpected.add("c4,2");
        docsExpected.add("d3,2");
        docsExpected.add("d4,2");
        assertEquals(docsExpected, getActual(json));
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 4
Source File: JobIT.java    From zentity with Apache License 2.0 5 votes vote down vote up
public void testJobArrays() throws Exception {
    int testResourceSet = TEST_RESOURCES_ARRAYS;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_arrays";
        Set<String> docsExpectedArrays = new TreeSet<>();
        docsExpectedArrays.add("1,0");
        docsExpectedArrays.add("2,1");

        Request q1 = new Request("POST", endpoint);
        q1.addParameter("_explanation", "true");
        q1.setEntity(TEST_PAYLOAD_JOB_ARRAYS);
        Response r1 = client.performRequest(q1);
        JsonNode j1 = Json.MAPPER.readTree(r1.getEntity().getContent());
        assertEquals(j1.get("hits").get("total").asInt(), 2);
        assertEquals(docsExpectedArrays, getActual(j1));

        for (JsonNode doc : j1.get("hits").get("hits")) {
            String attributesExpected = "";
            String explanationExpected = "";
            switch (doc.get("_id").asText()) {
                case "1":
                    attributesExpected = "{\"array\":[\"111\",\"222\",\"333\",\"444\"],\"string\":[\"abc\"]}";
                    explanationExpected = "{\"resolvers\":{\"array\":{\"attributes\":[\"array\"]},\"string\":{\"attributes\":[\"string\"]}},\"matches\":[{\"attribute\":\"array\",\"target_field\":\"array_2\",\"target_value\":[\"222\",null,\"222\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"array\",\"target_field\":\"array_4\",\"target_value\":[\"222\",\"333\",\"444\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"string\",\"target_field\":\"string\",\"target_value\":\"abc\",\"input_value\":\"abc\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}}]}";
                    break;
                case "2":
                    attributesExpected = "{\"array\":[\"444\",\"555\"],\"string\":[\"xyz\"]}";
                    explanationExpected = "{\"resolvers\":{\"array\":{\"attributes\":[\"array\"]}},\"matches\":[{\"attribute\":\"array\",\"target_field\":\"array_1\",\"target_value\":[\"444\"],\"input_value\":\"444\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}}]}";
                    break;
            }
            assertEquals(attributesExpected, Json.MAPPER.writeValueAsString(doc.get("_attributes")));
            assertEquals(explanationExpected, Json.MAPPER.writeValueAsString(doc.get("_explanation")));
        }

    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 5
Source File: ElasticsearchOps.java    From immutables with Apache License 2.0 5 votes vote down vote up
/**
 * Delete documents using query API
 * @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html">Delete by query API</a>
 */
Single<WriteResult> deleteByQuery(ObjectNode query) {
  Objects.requireNonNull(query, "query");
  Request request = new Request("POST", String.format("/%s/_delete_by_query", index));
  request.addParameter("refresh", "true");
  request.setJsonEntity(query.toString());
  return transport.execute(request).map(x -> WriteResult.unknown());
}
 
Example 6
Source File: JobIT.java    From zentity with Apache License 2.0 4 votes vote down vote up
public void testJobDataTypesDate() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a?max_hops=2&max_docs_per_query=2";
        Request postResolution = new Request("POST", endpoint);
        postResolution.addParameter("max_hops", "2");
        postResolution.addParameter("max_docs_per_query", "2");
        postResolution.setEntity(TEST_PAYLOAD_JOB_DATA_TYPES_DATE);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());

        /*
        Elasticsearch 7.0.0 - 7.2.0 has a different behavior when querying date ranges.

        To demonstrate, compare this query (below) with the test indices, data, and entity models on Elasticsearch
        versions 6.7.1 and 7.0.0:

        GET .zentity_test_index_d/_search
        {
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "type_date": {
                      "gte": "2000-01-01 00:00:01||-2s",
                      "lte": "2000-01-01 00:00:01||+2s",
                      "format": "yyyy-MM-dd HH:mm:ss"
                    }
                  }
                }
              ]
            }
          }
        }

        In 7.0.0 the result has a fourth hit ("_id" = "d3") where the "type_date" field is "2000-01-01T00:00:02.500",
        which is a half second greater than the 2s window that was specified in the search.

        We'll allow this behavior in the test, since this is a behavior of Elasticsearch and not zentity.
        */
        Properties props = new Properties();
        props.load(ZentityPlugin.class.getResourceAsStream("/plugin-descriptor.properties"));
        Set<String> dateBugVersions = new TreeSet<>();
        dateBugVersions.add("7.0.0");
        dateBugVersions.add("7.0.1");
        dateBugVersions.add("7.1.0");
        dateBugVersions.add("7.1.1");
        dateBugVersions.add("7.2.0");
        if (dateBugVersions.contains(props.getProperty("elasticsearch.version"))) {
            assertEquals(json.get("hits").get("total").asInt(), 15);
        } else {
            assertEquals(json.get("hits").get("total").asInt(), 13);
        }
        Set<String> docsExpected = new TreeSet<>();
        docsExpected.add("a1,0");
        docsExpected.add("a2,0");
        docsExpected.add("b0,0");
        docsExpected.add("c0,0");
        docsExpected.add("d0,0");
        docsExpected.add("d1,0");
        docsExpected.add("a3,1");
        docsExpected.add("b3,1");
        docsExpected.add("c1,1");
        docsExpected.add("d2,1");
        docsExpected.add("b1,2");
        docsExpected.add("c3,2");
        if (dateBugVersions.contains(props.getProperty("elasticsearch.version"))) {
            docsExpected.add("d3,1");
            docsExpected.add("a4,2");
            docsExpected.add("c4,2");
        } else {
            docsExpected.add("d3,2");
        }
        assertEquals(docsExpected, getActual(json));
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 7
Source File: JobIT.java    From zentity with Apache License 2.0 4 votes vote down vote up
public void testJobDataTypesDateTerm() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a?max_hops=2&max_docs_per_query=2";
        Request postResolution = new Request("POST", endpoint);
        postResolution.addParameter("max_hops", "2");
        postResolution.addParameter("max_docs_per_query", "2");
        postResolution.setEntity(TEST_PAYLOAD_JOB_DATA_TYPES_DATE_TERMS);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());

        /*
        Elasticsearch 7.0.0 - 7.2.0 has a different behavior when querying date ranges.

        To demonstrate, compare this query (below) with the test indices, data, and entity models on Elasticsearch
        versions 6.7.1 and 7.0.0:

        GET .zentity_test_index_d/_search
        {
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "type_date": {
                      "gte": "2000-01-01 00:00:01||-2s",
                      "lte": "2000-01-01 00:00:01||+2s",
                      "format": "yyyy-MM-dd HH:mm:ss"
                    }
                  }
                }
              ]
            }
          }
        }

        In 7.0.0 the result has a fourth hit ("_id" = "d3") where the "type_date" field is "2000-01-01T00:00:02.500",
        which is a half second greater than the 2s window that was specified in the search.

        We'll allow this behavior in the test, since this is a behavior of Elasticsearch and not zentity.
        */
        Properties props = new Properties();
        props.load(ZentityPlugin.class.getResourceAsStream("/plugin-descriptor.properties"));
        Set<String> dateBugVersions = new TreeSet<>();
        dateBugVersions.add("7.0.0");
        dateBugVersions.add("7.0.1");
        dateBugVersions.add("7.1.0");
        dateBugVersions.add("7.1.1");
        dateBugVersions.add("7.2.0");
        if (dateBugVersions.contains(props.getProperty("elasticsearch.version"))) {
            assertEquals(json.get("hits").get("total").asInt(), 15);
        } else {
            assertEquals(json.get("hits").get("total").asInt(), 13);
        }
        Set<String> docsExpected = new TreeSet<>();
        docsExpected.add("a1,0");
        docsExpected.add("a2,0");
        docsExpected.add("b0,0");
        docsExpected.add("c0,0");
        docsExpected.add("d0,0");
        docsExpected.add("d1,0");
        docsExpected.add("a3,1");
        docsExpected.add("b3,1");
        docsExpected.add("c1,1");
        docsExpected.add("d2,1");
        docsExpected.add("b1,2");
        docsExpected.add("c3,2");
        if (dateBugVersions.contains(props.getProperty("elasticsearch.version"))) {
            docsExpected.add("d3,1");
            docsExpected.add("a4,2");
            docsExpected.add("c4,2");
        } else {
            docsExpected.add("d3,2");
        }
        assertEquals(docsExpected, getActual(json));
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 8
Source File: JobIT.java    From zentity with Apache License 2.0 4 votes vote down vote up
public void testJobScore() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a";
        Request postResolution = new Request("POST", endpoint);
        postResolution.setEntity(TEST_PAYLOAD_JOB_NO_SCOPE);
        postResolution.addParameter("_explanation", "true");
        postResolution.addParameter("_score", "true");
        postResolution.addParameter("max_docs_per_query", "1");
        postResolution.addParameter("max_hops", "3");
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
        assertEquals(json.get("hits").get("total").asInt(), 14);
        for (JsonNode doc : json.get("hits").get("hits")) {
            switch (doc.get("_id").textValue()) {
                case "a0":
                case "b0":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.794, 0.0000000001);
                    break;
                case "a1":
                case "b1":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.5, 0.0000000001);
                    break;
                case "c0":
                case "d0":
                case "c2":
                case "d2":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.0, 0.0000000001);
                    break;
                case "a2":
                case "b2":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.8426393720609059, 0.0000000001);
                    break;
                case "c1":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.9356979368877253, 0.0000000001);
                    break;
                case "d1":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.9262128928820453, 0.0000000001);
                    break;
                case "a3":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.9684567702655289, 0.0000000001);
                    break;
                case "b3":
                    Assert.assertEquals(doc.get("_score").doubleValue(), 0.9680814702469515, 0.0000000001);
                    break;
                default:
                    Assert.fail();
            }
            for (JsonNode match : doc.get("_explanation").get("matches"))
                assertFalse(match.get("score").isMissingNode());
        }
    } finally {
        destroyTestResources(testResourceSet);
    }
}