|
36 | 36 | import org.elasticsearch.client.ml.DeleteForecastRequest;
|
37 | 37 | import org.elasticsearch.client.ml.DeleteJobRequest;
|
38 | 38 | import org.elasticsearch.client.ml.DeleteModelSnapshotRequest;
|
| 39 | +import org.elasticsearch.client.ml.FindFileStructureRequest; |
39 | 40 | import org.elasticsearch.client.ml.FlushJobRequest;
|
40 | 41 | import org.elasticsearch.client.ml.ForecastJobRequest;
|
41 | 42 | import org.elasticsearch.client.ml.GetBucketsRequest;
|
|
70 | 71 | import org.elasticsearch.client.ml.job.util.PageParams;
|
71 | 72 | import org.elasticsearch.common.Strings;
|
72 | 73 | import org.elasticsearch.common.bytes.BytesReference;
|
| 74 | +import org.elasticsearch.common.xcontent.XContentType; |
73 | 75 |
|
74 | 76 | import java.io.IOException;
|
75 | 77 |
|
@@ -648,4 +650,65 @@ static Request deleteFilter(DeleteFilterRequest deleteFilterRequest) {
|
648 | 650 | Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
|
649 | 651 | return request;
|
650 | 652 | }
|
| 653 | + |
| 654 | + static Request findFileStructure(FindFileStructureRequest findFileStructureRequest) { |
| 655 | + String endpoint = new EndpointBuilder() |
| 656 | + .addPathPartAsIs("_xpack") |
| 657 | + .addPathPartAsIs("ml") |
| 658 | + .addPathPartAsIs("find_file_structure") |
| 659 | + .build(); |
| 660 | + Request request = new Request(HttpPost.METHOD_NAME, endpoint); |
| 661 | + |
| 662 | + RequestConverters.Params params = new RequestConverters.Params(request); |
| 663 | + if (findFileStructureRequest.getLinesToSample() != null) { |
| 664 | + params.putParam(FindFileStructureRequest.LINES_TO_SAMPLE.getPreferredName(), |
| 665 | + findFileStructureRequest.getLinesToSample().toString()); |
| 666 | + } |
| 667 | + if (findFileStructureRequest.getTimeout() != null) { |
| 668 | + params.putParam(FindFileStructureRequest.TIMEOUT.getPreferredName(), findFileStructureRequest.getTimeout().toString()); |
| 669 | + } |
| 670 | + if (findFileStructureRequest.getCharset() != null) { |
| 671 | + params.putParam(FindFileStructureRequest.CHARSET.getPreferredName(), findFileStructureRequest.getCharset()); |
| 672 | + } |
| 673 | + if (findFileStructureRequest.getFormat() != null) { |
| 674 | + params.putParam(FindFileStructureRequest.FORMAT.getPreferredName(), findFileStructureRequest.getFormat().toString()); |
| 675 | + } |
| 676 | + if (findFileStructureRequest.getColumnNames() != null) { |
| 677 | + params.putParam(FindFileStructureRequest.COLUMN_NAMES.getPreferredName(), |
| 678 | + Strings.collectionToCommaDelimitedString(findFileStructureRequest.getColumnNames())); |
| 679 | + } |
| 680 | + if (findFileStructureRequest.getHasHeaderRow() != null) { |
| 681 | + params.putParam(FindFileStructureRequest.HAS_HEADER_ROW.getPreferredName(), |
| 682 | + findFileStructureRequest.getHasHeaderRow().toString()); |
| 683 | + } |
| 684 | + if (findFileStructureRequest.getDelimiter() != null) { |
| 685 | + params.putParam(FindFileStructureRequest.DELIMITER.getPreferredName(), |
| 686 | + findFileStructureRequest.getDelimiter().toString()); |
| 687 | + } |
| 688 | + if (findFileStructureRequest.getQuote() != null) { |
| 689 | + params.putParam(FindFileStructureRequest.QUOTE.getPreferredName(), findFileStructureRequest.getQuote().toString()); |
| 690 | + } |
| 691 | + if (findFileStructureRequest.getShouldTrimFields() != null) { |
| 692 | + params.putParam(FindFileStructureRequest.SHOULD_TRIM_FIELDS.getPreferredName(), |
| 693 | + findFileStructureRequest.getShouldTrimFields().toString()); |
| 694 | + } |
| 695 | + if (findFileStructureRequest.getGrokPattern() != null) { |
| 696 | + params.putParam(FindFileStructureRequest.GROK_PATTERN.getPreferredName(), findFileStructureRequest.getGrokPattern()); |
| 697 | + } |
| 698 | + if (findFileStructureRequest.getTimestampFormat() != null) { |
| 699 | + params.putParam(FindFileStructureRequest.TIMESTAMP_FORMAT.getPreferredName(), findFileStructureRequest.getTimestampFormat()); |
| 700 | + } |
| 701 | + if (findFileStructureRequest.getTimestampField() != null) { |
| 702 | + params.putParam(FindFileStructureRequest.TIMESTAMP_FIELD.getPreferredName(), findFileStructureRequest.getTimestampField()); |
| 703 | + } |
| 704 | + if (findFileStructureRequest.getExplain() != null) { |
| 705 | + params.putParam(FindFileStructureRequest.EXPLAIN.getPreferredName(), findFileStructureRequest.getExplain().toString()); |
| 706 | + } |
| 707 | + |
| 708 | + BytesReference sample = findFileStructureRequest.getSample(); |
| 709 | + BytesRef source = sample.toBytesRef(); |
| 710 | + HttpEntity byteEntity = new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(XContentType.JSON)); |
| 711 | + request.setEntity(byteEntity); |
| 712 | + return request; |
| 713 | + } |
651 | 714 | }
|
0 commit comments