Search in sources :

Example 71 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project elasticsearch-jetty by sonian.

the class ESLoginService method loadUser.

@Override
public UserIdentity loadUser(String user) {
    Log.debug("attempting to load user [{}]", user);
    try {
        GetResponse response = client.prepareGet(authIndex, authType, user).setFields(passwordField, rolesField).execute().actionGet();
        if (response.isExists()) {
            Log.debug("user [{}] exists; looking for credentials...", user);
            Credential credential = null;
            GetField passwordGetField = response.getField(passwordField);
            if (passwordGetField != null) {
                Log.debug("user [{}] using password auth", user);
                credential = Credential.getCredential((String) passwordGetField.getValue());
            }
            String[] roles = getStringValues(response.getField(rolesField));
            return putUser(user, credential, roles);
        }
    } catch (IndexMissingException e) {
        Log.warn("no auth index [{}]", authIndex);
    } catch (Exception e) {
        Log.warn("error finding user [" + user + "] in [" + authIndex + "]", e);
    }
    return null;
}
Also used : Credential(org.eclipse.jetty.util.security.Credential) GetField(org.elasticsearch.index.get.GetField) IndexMissingException(org.elasticsearch.indices.IndexMissingException) GetResponse(org.elasticsearch.action.get.GetResponse) IndexMissingException(org.elasticsearch.indices.IndexMissingException)

Example 72 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project elasticsearch-river-neo4j by sksamuel.

the class Neo4jRiverIntTest method setupElasticAndNeo4jClient.

@Before
public void setupElasticAndNeo4jClient() throws Exception {
    Settings globalSettings = settingsBuilder().loadFromClasspath("settings.yml").build();
    String json = copyToStringFromClasspath("/neo4j-inttest-river.json");
    Settings riverSettings = settingsBuilder().loadFromSource(json).build();
    index = riverSettings.get("index.name");
    type = riverSettings.get("index.type");
    String uri = riverSettings.get("neo4j.uri");
    logger.debug("Connecting to neo4j @ {}", uri);
    db = new SpringCypherRestGraphDatabase(uri);
    logger.debug("Starting local elastic...");
    Tuple<Settings, Environment> initialSettings = InternalSettingsPerparer.prepareSettings(globalSettings, true);
    if (!initialSettings.v2().configFile().exists()) {
        FileSystemUtils.mkdirs(initialSettings.v2().configFile());
    }
    if (!initialSettings.v2().logsFile().exists()) {
        FileSystemUtils.mkdirs(initialSettings.v2().logsFile());
    }
    node = nodeBuilder().local(true).settings(globalSettings).node();
    logger.info("Create river [{}]", river);
    node.client().prepareIndex("_river", river, "_meta").setSource(json).execute().actionGet();
    logger.debug("Running Cluster Health");
    ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
    logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
    GetResponse response = node.client().prepareGet("_river", river, "_meta").execute().actionGet();
    assertTrue(response.isExists());
    logger.debug("...elasticized ok");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) SpringCypherRestGraphDatabase(org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase) Environment(org.elasticsearch.env.Environment) QueryBuilders.queryString(org.elasticsearch.index.query.QueryBuilders.queryString) GetResponse(org.elasticsearch.action.get.GetResponse) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 73 with GetResponse

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

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testGet.

@Test
public void testGet() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    sendBody("direct:index", map);
    String indexId = template.requestBody("direct:index", map, String.class);
    assertNotNull("indexId should be set", indexId);
    //now, verify GET succeeded
    GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 74 with GetResponse

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

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testGetWithHeaders.

@Test
public void testGetWithHeaders() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    //now, verify GET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
    GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
}
Also used : HashMap(java.util.HashMap) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 75 with GetResponse

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

the class ElasticsearchGetSearchDeleteExistsUpdateTest method getRequestBody.

@Test
public void getRequestBody() throws Exception {
    String prefix = createPrefix();
    // given
    GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
    // when
    String documentId = template.requestBody("direct:index", new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
    GetResponse response = template.requestBody("direct:get", request.id(documentId), GetResponse.class);
    // then
    assertThat(response, notNullValue());
    assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

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