[ML] Change delimiter in the names of state docs (elastic/x-pack-elasticsearch#768)

Original commit: elastic/x-pack-elasticsearch@34acda3ffe
This commit is contained in:
David Kyle 2017-03-17 17:08:29 +00:00
parent 3935d82763
commit 30ea37943c
8 changed files with 32 additions and 18 deletions

View File

@ -114,7 +114,7 @@ public class JobDataDeleter {
// too big and has no mappings.
// Note: state docs are 1-based
for (int i = 1; i <= docCount; ++i) {
String stateId = snapshotDocId + '_' + i;
String stateId = snapshotDocId + '#' + i;
bulkRequestBuilder.add(client.prepareDelete(stateIndexName, ModelState.TYPE.getPreferredName(), stateId));
++deletedModelStateCount;
}

View File

@ -927,7 +927,7 @@ public class JobProvider {
// the order the C++ process expects.
int numDocs = modelSnapshot.getSnapshotDocCount();
for (docNum = 1; docNum <= numDocs; ++docNum) {
String docId = String.format(Locale.ROOT, "%s_%d", ModelSnapshot.documentId(modelSnapshot), docNum);
String docId = String.format(Locale.ROOT, "%s#%d", ModelSnapshot.documentId(modelSnapshot), docNum);
LOGGER.trace("ES API CALL: get ID {} type {} from index {}", docId, ModelState.TYPE, indexName);

View File

@ -24,8 +24,8 @@ import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.PrefixQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.query.WildcardQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
@ -156,13 +156,13 @@ public class JobStorageDeletionTask extends Task {
}
private void deleteCategorizerState(String jobId, Client client, ActionListener<Boolean> finishedHandler) {
SearchRequest searchRequest = new SearchRequest();
SearchRequest searchRequest = new SearchRequest(AnomalyDetectorsIndex.jobStateIndexName());
DeleteByQueryRequest request = new DeleteByQueryRequest(searchRequest);
PrefixQueryBuilder query = new PrefixQueryBuilder(UidFieldMapper.NAME, Uid.createUid(CategorizerState.TYPE, jobId));
searchRequest.source(new SearchSourceBuilder().query(query));
searchRequest.indicesOptions(JobProvider.addIgnoreUnavailable(IndicesOptions.lenientExpandOpen()));
request.setSlices(5);
searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
WildcardQueryBuilder query = new WildcardQueryBuilder(UidFieldMapper.NAME, Uid.createUid(CategorizerState.TYPE, jobId + "#*"));
searchRequest.source(new SearchSourceBuilder().query(query));
client.execute(MlDeleteByQueryAction.INSTANCE, request, new ActionListener<BulkByScrollResponse>() {
@Override
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {

View File

@ -19,7 +19,7 @@ public class CategorizerState {
public static final String TYPE = "categorizer_state";
public static final String categorizerStateDocId(String jobId, int docNum) {
return jobId + "_" + docNum;
return jobId + "#" + docNum;
}
private CategorizerState() {

View File

@ -169,7 +169,6 @@ public class DeleteExpiredDataIT extends SecurityIntegTestCase {
assertThat(getRecords(job.getId()).size(), equalTo(1));
List<ModelSnapshot> modelSnapshots = getModelSnapshots(job.getId());
assertThat(modelSnapshots.size(), equalTo(2));
}
long totalModelSizeStatsBeforeDelete = client().prepareSearch("*").setTypes("result")

View File

@ -38,7 +38,6 @@ import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.ml.MlMetadata;
import org.elasticsearch.xpack.ml.action.DeleteJobAction;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery;
@ -70,7 +69,6 @@ import java.util.function.Consumer;
import static org.elasticsearch.xpack.ml.job.config.JobTests.buildJobBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
@ -1039,11 +1037,11 @@ public class JobProviderTests extends ESTestCase {
GetResponse modelStateGetResponse2 = createGetResponse(true, modelState);
MockClientBuilder clientBuilder = new MockClientBuilder(CLUSTER_NAME).addClusterStatusYellowResponse()
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), CategorizerState.TYPE, JOB_ID + "_1", categorizerStateGetResponse1)
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), CategorizerState.TYPE, JOB_ID + "_2", categorizerStateGetResponse2)
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), ModelState.TYPE.getPreferredName(), JOB_ID + "-123_1",
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), CategorizerState.TYPE, JOB_ID + "#1", categorizerStateGetResponse1)
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), CategorizerState.TYPE, JOB_ID + "#2", categorizerStateGetResponse2)
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), ModelState.TYPE.getPreferredName(), JOB_ID + "-123#1",
modelStateGetResponse1)
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), ModelState.TYPE.getPreferredName(), JOB_ID + "-123_2",
.prepareGet(AnomalyDetectorsIndex.jobStateIndexName(), ModelState.TYPE.getPreferredName(), JOB_ID + "-123#2",
modelStateGetResponse2);
JobProvider provider = createProvider(clientBuilder.build());

View File

@ -51,7 +51,7 @@ setup:
index:
index: .ml-state
type: model_state
id: "foo-inactive-snapshot_1"
id: "foo-inactive-snapshot#1"
body: >
{
"state": "a"
@ -61,7 +61,7 @@ setup:
index:
index: .ml-state
type: model_state
id: "foo-inactive-snapshot_2"
id: "foo-inactive-snapshot#2"
body: >
{
"state": "b"

View File

@ -163,6 +163,23 @@ setup:
job_id: farequote2
- match: {count: 4}
# Put some categorizer state
- do:
index:
index: .ml-state
type: categorizer_state
id: farequote2#1
body:
key: value
- do:
index:
index: .ml-state
type: categorizer_state
id: farequote2#2
body:
key: value
- do:
xpack.ml.delete_job:
job_id: "farequote"
@ -179,7 +196,7 @@ setup:
- do:
count:
index: .ml-state
- match: {count: 2}
- match: {count: 4}
- do:
count: