-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: Adding ml get filters api #35502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benwtrent
merged 3 commits into
elastic:master
from
benwtrent:feature/hlrc-ml-get-filter
Nov 13, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetFiltersRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.client.ml.job.config.MlFilter; | ||
import org.elasticsearch.client.ml.job.util.PageParams; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A request to retrieve {@link MlFilter}s | ||
*/ | ||
public class GetFiltersRequest extends ActionRequest implements ToXContentObject { | ||
|
||
public static final ObjectParser<GetFiltersRequest, Void> PARSER = | ||
new ObjectParser<>("get_filters_request", GetFiltersRequest::new); | ||
|
||
static { | ||
PARSER.declareString(GetFiltersRequest::setId, MlFilter.ID); | ||
PARSER.declareInt(GetFiltersRequest::setFrom, PageParams.FROM); | ||
PARSER.declareInt(GetFiltersRequest::setSize, PageParams.SIZE); | ||
} | ||
|
||
private String filterId; | ||
private Integer from; | ||
private Integer size; | ||
|
||
public String getFilterId() { | ||
return filterId; | ||
} | ||
|
||
public Integer getFrom() { | ||
return from; | ||
} | ||
|
||
public Integer getSize() { | ||
return size; | ||
} | ||
|
||
/** | ||
* Sets the filter id | ||
* @param filterId the filter id | ||
*/ | ||
public void setId(String filterId) { | ||
this.filterId = filterId; | ||
} | ||
|
||
/** | ||
* Sets the number of filters to skip. | ||
* @param from set the `from` parameter | ||
*/ | ||
public void setFrom(Integer from) { | ||
this.from = from; | ||
} | ||
|
||
/** | ||
* Sets the number of filters to return. | ||
* @param size set the `size` parameter | ||
*/ | ||
public void setSize(Integer size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
if (filterId != null) { | ||
builder.field(MlFilter.ID.getPreferredName(), filterId); | ||
} | ||
if (from != null) { | ||
builder.field(PageParams.FROM.getPreferredName(), from); | ||
} | ||
if (size != null) { | ||
builder.field(PageParams.SIZE.getPreferredName(), size); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetFiltersRequest request = (GetFiltersRequest) obj; | ||
return Objects.equals(filterId, request.filterId) | ||
&& Objects.equals(from, request.from) | ||
&& Objects.equals(size, request.size); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(filterId, from, size); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetFiltersResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.client.ml.job.config.MlFilter; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
/** | ||
* Contains a {@link List} of the found {@link MlFilter} objects and the total count found | ||
*/ | ||
public class GetFiltersResponse extends AbstractResultResponse<MlFilter> { | ||
|
||
public static final ParseField RESULTS_FIELD = new ParseField("filters"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetFiltersResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("get_filters_response", true, | ||
a -> new GetFiltersResponse((List<MlFilter.Builder>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), MlFilter.PARSER, RESULTS_FIELD); | ||
PARSER.declareLong(constructorArg(), AbstractResultResponse.COUNT); | ||
} | ||
|
||
GetFiltersResponse(List<MlFilter.Builder> filters, long count) { | ||
super(RESULTS_FIELD, filters.stream().map(MlFilter.Builder::build).collect(Collectors.toList()), count); | ||
} | ||
|
||
/** | ||
* The collection of {@link MlFilter} objects found in the query | ||
*/ | ||
public List<MlFilter> filters() { | ||
return results; | ||
} | ||
|
||
public static GetFiltersResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(results, count); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
GetFiltersResponse other = (GetFiltersResponse) obj; | ||
return Objects.equals(results, other.results) && count == other.count; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.