Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
[Remove] Type from Client.prepare(Index,Delete,Update) (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#2253)

Removes the type parameter from Client.prepare(Index,Delete,Update) and
everywhere it's used throughout the codebase except for prepareIndex(index,
type, id) which is removed in a follow up.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize authored Feb 25, 2022
1 parent 9f6e2e5 commit 8b48207
Show file tree
Hide file tree
Showing 157 changed files with 795 additions and 951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testFailureInConditionalProcessor() {

Exception e = expectThrows(
Exception.class,
() -> client().prepareIndex("index", "doc")
() -> client().prepareIndex("index")
.setId("1")
.setSource("x", 0)
.setPipeline(pipelineId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ public void testInvalidUpdateScript() throws Exception {
ensureGreen("test_index");
indexRandom(true, client().prepareIndex("test_index", "doc", "1").setSource("text_field", "text"));
UpdateRequestBuilder urb = client().prepareUpdate().setIndex("test_index");
urb.setType("doc");
urb.setId("1");
urb.setScript(new Script(ScriptType.INLINE, ExpressionScriptEngine.NAME, "0", Collections.emptyMap()));
urb.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public void testAllOpsDisabledIndexedScripts() throws IOException {
.get();
client().prepareIndex("test", "scriptTest", "1").setSource("{\"theField\":\"foo\"}", XContentType.JSON).get();
try {
client().prepareUpdate("test", "scriptTest", "1")
.setScript(new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
.get();
client().prepareUpdate("test", "1").setScript(new Script(ScriptType.STORED, null, "script1", Collections.emptyMap())).get();
fail("update script should have been rejected");
} catch (Exception e) {
assertThat(e.getMessage(), containsString("failed to execute script"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void testWithDeletes() throws Exception {
* the updates cause that.
*/
UpdateResponse updateResponse;
updateResponse = client().prepareUpdate(indexName, "doc", idToUpdate)
updateResponse = client().prepareUpdate(indexName, idToUpdate)
.setRouting("1")
.setDoc(Requests.INDEX_CONTENT_TYPE, "count", 1)
.setDetectNoop(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public void testParentChildQueriesCanHandleNoRelevantTypesInIndex() throws Excep
assertNoFailures(response);
assertThat(response.getHits().getTotalHits().value, equalTo(0L));

client().prepareIndex("test", "doc")
client().prepareIndex("test")
.setSource(jsonBuilder().startObject().field("text", "value").endObject())
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ public void testDisallowExpensiveQueries() throws IOException {
.addMapping("_doc", "id", "type=keyword", "field1", "type=keyword", "query", "type=percolator")
);

client().prepareIndex("test", "_doc")
client().prepareIndex("test")
.setId("1")
.setSource(jsonBuilder().startObject().field("id", "1").field("query", matchQuery("field1", "value")).endObject())
.get();
Expand Down Expand Up @@ -1264,13 +1264,13 @@ public void testWrappedWithConstantScore() throws Exception {

assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", "d", "type=date", "q", "type=percolator"));

client().prepareIndex("test", "_doc")
client().prepareIndex("test")
.setId("1")
.setSource(jsonBuilder().startObject().field("q", boolQuery().must(rangeQuery("d").gt("now"))).endObject())
.execute()
.actionGet();

client().prepareIndex("test", "_doc")
client().prepareIndex("test")
.setId("2")
.setSource(jsonBuilder().startObject().field("q", boolQuery().must(rangeQuery("d").lt("now"))).endObject())
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.MatchAllQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.rankeval.PrecisionAtK.Detail;
Expand Down Expand Up @@ -74,29 +73,18 @@ public void setup() {
createIndex(TEST_INDEX);
ensureGreen();

client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "1")
client().prepareIndex(TEST_INDEX)
.setId("1")
.setSource("id", 1, "text", "berlin", "title", "Berlin, Germany", "population", 3670622)
.get();
client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "2")
.setSource("id", 2, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "3")
.setSource("id", 3, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "4")
.setSource("id", 4, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "5")
.setSource("id", 5, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex(TEST_INDEX, MapperService.SINGLE_MAPPING_NAME, "6")
.setSource("id", 6, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex(TEST_INDEX).setId("2").setSource("id", 2, "text", "amsterdam", "population", 851573).get();
client().prepareIndex(TEST_INDEX).setId("3").setSource("id", 3, "text", "amsterdam", "population", 851573).get();
client().prepareIndex(TEST_INDEX).setId("4").setSource("id", 4, "text", "amsterdam", "population", 851573).get();
client().prepareIndex(TEST_INDEX).setId("5").setSource("id", 5, "text", "amsterdam", "population", 851573).get();
client().prepareIndex(TEST_INDEX).setId("6").setSource("id", 6, "text", "amsterdam", "population", 851573).get();

// add another index for testing closed indices etc...
client().prepareIndex("test2", MapperService.SINGLE_MAPPING_NAME, "7")
.setSource("id", 7, "text", "amsterdam", "population", 851573)
.get();
client().prepareIndex("test2").setId("7").setSource("id", 7, "text", "amsterdam", "population", 851573).get();
refresh();

// set up an alias that can also be used in tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testDeleteByQueryOnReadOnlyAllowDeleteIndex() throws Exception {
final int docs = randomIntBetween(1, 50);
List<IndexRequestBuilder> builders = new ArrayList<>();
for (int i = 0; i < docs; i++) {
builders.add(client().prepareIndex("test", "test").setId(Integer.toString(i)).setSource("field", 1));
builders.add(client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", 1));
}
indexRandom(true, true, true, builders);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testConcurrentDeleteByQueriesOnDifferentDocs() throws Throwable {
List<IndexRequestBuilder> builders = new ArrayList<>();
for (int i = 0; i < docs; i++) {
for (int t = 0; t < threads.length; t++) {
builders.add(client().prepareIndex("test", "doc").setSource("field", t));
builders.add(client().prepareIndex("test").setSource("field", t));
}
}
indexRandom(true, true, true, builders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected Settings nodeSettings() {

@Before
public void setupSourceIndex() {
client().prepareIndex("source", "test").setSource("test", "test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
client().prepareIndex("source").setSource("test", "test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
public void testDeprecatedSort() {
int max = between(2, 20);
for (int i = 0; i < max; i++) {
client().prepareIndex("source", "_doc").setId(Integer.toString(i)).setSource("foo", i).get();
client().prepareIndex("source").setId(Integer.toString(i)).setSource("foo", i).get();
}

client().admin().indices().prepareRefresh("source").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void testCase(
// Build the test data. Don't use indexRandom because that won't work consistently with such small thread pools.
BulkRequestBuilder bulk = client().prepareBulk();
for (int i = 0; i < DOC_COUNT; i++) {
bulk.add(client().prepareIndex("source", "test").setSource("foo", "bar " + i));
bulk.add(client().prepareIndex("source").setSource("foo", "bar " + i));
}

Retry retry = new Retry(BackoffPolicy.exponentialBackoff(), client().threadPool());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public void testSimpleWorkflow() {

logger.info("--> delete some data");
for (int i = 0; i < 50; i++) {
client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get();
client.prepareDelete("test-idx-1", Integer.toString(i)).get();
}
for (int i = 50; i < 100; i++) {
client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get();
client.prepareDelete("test-idx-2", Integer.toString(i)).get();
}
for (int i = 0; i < 100; i += 2) {
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
client.prepareDelete("test-idx-3", Integer.toString(i)).get();
}
client().admin().indices().prepareRefresh().get();
assertThat(count(client, "test-idx-1"), equalTo(50L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void waitForTaskCompletion(Task task) {}
}
// Need to run the task in a separate thread because node client's .execute() is blocked by our task listener
index = new Thread(() -> {
IndexResponse indexResponse = client().prepareIndex("test", "test").setSource("test", "test").get();
IndexResponse indexResponse = client().prepareIndex("test").setSource("test", "test").get();
assertArrayEquals(ReplicationResponse.EMPTY, indexResponse.getShardInfo().getFailures());
});
index.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ protected void setUpRepository() throws Exception {

int docs = between(10, 100);
for (int i = 0; i < docs; i++) {
client().prepareIndex(INDEX_NAME, "type").setSource("test", "init").execute().actionGet();
client().prepareIndex(INDEX_NAME).setSource("test", "init").execute().actionGet();
}
docs = between(10, 100);
for (int i = 0; i < docs; i++) {
client().prepareIndex(OTHER_INDEX_NAME, "type").setSource("test", "init").execute().actionGet();
client().prepareIndex(OTHER_INDEX_NAME).setSource("test", "init").execute().actionGet();
}

logger.info("--> register a repository");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testCreateCloneIndex() {
).get();
final int docs = randomIntBetween(0, 128);
for (int i = 0; i < docs; i++) {
client().prepareIndex("source", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("source").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
internalCluster().ensureAtLeastNumDataNodes(2);
// ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testCreateCloneIndex() {
}

for (int i = docs; i < 2 * docs; i++) {
client().prepareIndex("target", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void testCreateAndDeleteIndexConcurrently() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
int numDocs = randomIntBetween(1, 10);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get();
client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
}
synchronized (indexVersionLock) { // not necessarily needed here but for completeness we lock here too
indexVersion.incrementAndGet();
Expand All @@ -289,7 +289,7 @@ public void onResponse(AcknowledgedResponse deleteIndexResponse) {
public void run() {
try {
// recreate that index
client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get();
client().prepareIndex("test").setSource("index_version", indexVersion.get()).get();
synchronized (indexVersionLock) {
// we sync here since we have to ensure that all indexing operations below for a given ID are done before
// we increment the index version otherwise a doc that is in-flight could make it into an index that it
Expand All @@ -315,7 +315,7 @@ public void onFailure(Exception e) {
for (int i = 0; i < numDocs; i++) {
try {
synchronized (indexVersionLock) {
client().prepareIndex("test", "test")
client().prepareIndex("test")
.setSource("index_version", indexVersion.get())
.setTimeout(TimeValue.timeValueSeconds(10))
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void testCreateShrinkIndex() {
).get();
final int docs = randomIntBetween(0, 128);
for (int i = 0; i < docs; i++) {
client().prepareIndex("source", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("source").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin()
.cluster()
Expand Down Expand Up @@ -393,7 +393,7 @@ public void testCreateShrinkIndex() {
}

for (int i = docs; i < 2 * docs; i++) {
client().prepareIndex("target", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(client().prepareSearch("target").setSize(2 * size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 2 * docs);
Expand All @@ -420,7 +420,7 @@ public void testCreateShrinkIndexFails() throws Exception {
Settings.builder().put(indexSettings()).put("number_of_shards", randomIntBetween(2, 7)).put("number_of_replicas", 0)
).get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("source").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin()
.cluster()
Expand Down Expand Up @@ -595,7 +595,7 @@ public void testCreateShrinkWithIndexSort() throws Exception {

// ... and that the index sort is also applied to updates
for (int i = 20; i < 40; i++) {
client().prepareIndex("target", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertSortedSegments("target", expectedIndexSort);
Expand All @@ -606,7 +606,7 @@ public void testShrinkCommitsMergeOnIdle() throws Exception {
Settings.builder().put(indexSettings()).put("index.number_of_replicas", 0).put("number_of_shards", 5)
).get();
for (int i = 0; i < 30; i++) {
client().prepareIndex("source", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("source").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
client().admin().indices().prepareFlush("source").get();
ImmutableOpenMap<String, DiscoveryNode> dataNodes = client().admin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void testCreateSplitIndex() throws Exception {
).get();
final int docs = randomIntBetween(0, 128);
for (int i = 0; i < docs; i++) {
client().prepareIndex("source", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("source").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
// ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
// if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due
Expand Down Expand Up @@ -486,7 +486,7 @@ public void testCreateSplitIndex() throws Exception {
}

for (int i = docs; i < 2 * docs; i++) {
client().prepareIndex("target", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertHitCount(
Expand Down Expand Up @@ -580,7 +580,7 @@ public void testCreateSplitWithIndexSort() throws Exception {

// ... and that the index sort is also applied to updates
for (int i = 20; i < 40; i++) {
client().prepareIndex("target", "type").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
}
flushAndRefresh();
assertSortedSegments("target", expectedIndexSort);
Expand Down
Loading

0 comments on commit 8b48207

Please sign in to comment.