Search in sources :

Example 81 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project jena by apache.

the class TextIndexESIT method testDeleteWhenNoneExists.

@Test
public void testDeleteWhenNoneExists() {
    GetResponse response = transportClient.prepareGet(INDEX_NAME, DOC_TYPE, "http://example/x3").get();
    Assert.assertFalse(response.isExists());
    Assert.assertNotNull(classToTest);
    classToTest.deleteEntity(entity("http://example/x3", "label", "doesnt matter"));
    response = transportClient.prepareGet(INDEX_NAME, DOC_TYPE, "http://example/x3").get();
    Assert.assertFalse(response.isExists());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Example 82 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project jena by apache.

the class TextIndexES method get.

/**
     * Get an Entity given the subject Id
     * @param uri the subject Id of the entity
     * @return a map of field name and field values;
     */
@Override
public Map<String, Node> get(String uri) {
    GetResponse response;
    Map<String, Node> result = new HashMap<>();
    if (uri != null) {
        response = client.prepareGet(indexName, docDef.getEntityField(), uri).get();
        if (response != null && !response.isSourceEmpty()) {
            String entityField = response.getId();
            Node entity = NodeFactory.createURI(entityField);
            result.put(docDef.getEntityField(), entity);
            Map<String, Object> source = response.getSource();
            for (String field : docDef.fields()) {
                Object fieldResponse = source.get(field);
                if (fieldResponse == null) {
                    //We wont return it.
                    continue;
                } else if (fieldResponse instanceof List<?>) {
                    //We are storing the values of fields as a List always.
                    //If there are values stored in the list, then we return the first value,
                    // else we do not include the field in the returned Map of Field -> Node Mapping
                    List<?> responseList = (List<?>) fieldResponse;
                    if (responseList != null && responseList.size() > 0) {
                        String fieldValue = (String) responseList.get(0);
                        Node fieldNode = NodeFactoryExtra.createLiteralNode(fieldValue, null, null);
                        result.put(field, fieldNode);
                    }
                }
            }
        }
    }
    return result;
}
Also used : Node(org.apache.jena.graph.Node) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 83 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project fess by codelibs.

the class FessEsClient method get.

protected <T> T get(final String index, final String type, final String id, final SearchCondition<GetRequestBuilder> condition, final SearchResult<T, GetRequestBuilder, GetResponse> searchResult) {
    final long startTime = System.currentTimeMillis();
    GetResponse response = null;
    final GetRequestBuilder requestBuilder = client.prepareGet(index, type, id);
    if (condition.build(requestBuilder)) {
        response = requestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexSearchTimeout());
    }
    final long execTime = System.currentTimeMillis() - startTime;
    return searchResult.build(requestBuilder, execTime, OptionalEntity.ofNullable(response, () -> {
    }));
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 84 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project play2-elasticsearch by cleverage.

the class IndexService method get.

/**
     * Get a reponse for a simple request
     * @param indexName
     * @param indexType
     * @param id
     * @return
     */
public static GetResponse get(String indexName, String indexType, String id) {
    GetRequestBuilder getRequestBuilder = IndexClient.client.prepareGet(indexName, indexType, id);
    GetResponse getResponse = getRequestBuilder.execute().actionGet();
    return getResponse;
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)84 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)22 Test (org.junit.Test)18 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 HashMap (java.util.HashMap)11 GetRequest (org.elasticsearch.action.get.GetRequest)11 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)10 Script (org.elasticsearch.script.Script)9 Settings (org.elasticsearch.common.settings.Settings)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 IOException (java.io.IOException)7 Map (java.util.Map)7 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 CompiledScript (org.elasticsearch.script.CompiledScript)7 ExecutableScript (org.elasticsearch.script.ExecutableScript)7 SearchScript (org.elasticsearch.script.SearchScript)7 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)6 IndexResponse (org.elasticsearch.action.index.IndexResponse)5 VersionConflictEngineException (org.elasticsearch.index.engine.VersionConflictEngineException)5 Path (java.nio.file.Path)4