Search in sources :

Example 21 with IndexRequest

use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.

the class RestReindexActionTests method testReindexFromRemoteRequestParsing.

public void testReindexFromRemoteRequestParsing() throws IOException {
    BytesReference request;
    try (XContentBuilder b = JsonXContent.contentBuilder()) {
        b.startObject();
        {
            b.startObject("source");
            {
                b.startObject("remote");
                {
                    b.field("host", "http://localhost:9200");
                }
                b.endObject();
                b.field("index", "source");
            }
            b.endObject();
            b.startObject("dest");
            {
                b.field("index", "dest");
            }
            b.endObject();
        }
        b.endObject();
        request = b.bytes();
    }
    try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
        ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
        RestReindexAction.PARSER.parse(p, r, null);
        assertEquals("localhost", r.getRemoteInfo().getHost());
        assertArrayEquals(new String[] { "source" }, r.getSearchRequest().indices());
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 22 with IndexRequest

use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.

the class ReindexMetadataTests method testRoutingCopiedByDefault.

public void testRoutingCopiedByDefault() throws Exception {
    IndexRequest index = new IndexRequest();
    action().copyMetadata(AbstractAsyncBulkByScrollAction.wrap(index), doc().setRouting("foo"));
    assertEquals("foo", index.routing());
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 23 with IndexRequest

use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.

the class ReindexRequestTests method newRequest.

@Override
protected ReindexRequest newRequest() {
    ReindexRequest reindex = new ReindexRequest(new SearchRequest(), new IndexRequest());
    reindex.getSearchRequest().indices("source");
    reindex.getDestination().index("dest");
    return reindex;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 24 with IndexRequest

use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.

the class ReindexScriptTests method testSetVersion.

public void testSetVersion() throws Exception {
    Number version = randomFrom(new Number[] { null, 234, 234L });
    IndexRequest index = applyScript((Map<String, Object> ctx) -> ctx.put("_version", version));
    if (version == null) {
        assertEquals(Versions.MATCH_ANY, index.version());
    } else {
        assertEquals(version.longValue(), index.version());
    }
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest) Map(java.util.Map)

Example 25 with IndexRequest

use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.

the class ReindexScriptTests method testSetType.

public void testSetType() throws Exception {
    Object type = randomFrom(new Object[] { 234, 234L, "pancake" });
    IndexRequest index = applyScript((Map<String, Object> ctx) -> ctx.put("_type", type));
    assertEquals(type.toString(), index.type());
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest) Map(java.util.Map)

Aggregations

IndexRequest (org.elasticsearch.action.index.IndexRequest)175 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)34 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)32 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)32 IOException (java.io.IOException)28 Test (org.junit.Test)27 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)25 ElasticsearchException (org.elasticsearch.ElasticsearchException)20 IndexResponse (org.elasticsearch.action.index.IndexResponse)17 HashMap (java.util.HashMap)16 Map (java.util.Map)14 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)14 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)13 GetRequest (org.elasticsearch.action.get.GetRequest)13 BytesReference (org.elasticsearch.common.bytes.BytesReference)11 ArrayList (java.util.ArrayList)10 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)9 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)8 Settings (org.elasticsearch.common.settings.Settings)8