RestFieldCapabilitiesAction.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Licensed to Elasticsearch under one or more contributor
  3. * license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright
  5. * ownership. Elasticsearch licenses this file to you under
  6. * the Apache License, Version 2.0 (the "License"); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.elasticsearch.rest.action;
  20. import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
  21. import org.elasticsearch.action.support.IndicesOptions;
  22. import org.elasticsearch.client.node.NodeClient;
  23. import org.elasticsearch.common.Strings;
  24. import org.elasticsearch.common.settings.Settings;
  25. import org.elasticsearch.rest.BaseRestHandler;
  26. import org.elasticsearch.rest.RestController;
  27. import org.elasticsearch.rest.RestRequest;
  28. import java.io.IOException;
  29. import static org.elasticsearch.rest.RestRequest.Method.GET;
  30. import static org.elasticsearch.rest.RestRequest.Method.POST;
  31. public class RestFieldCapabilitiesAction extends BaseRestHandler {
  32. public RestFieldCapabilitiesAction(Settings settings, RestController controller) {
  33. super(settings);
  34. controller.registerHandler(GET, "/_field_caps", this);
  35. controller.registerHandler(POST, "/_field_caps", this);
  36. controller.registerHandler(GET, "/{index}/_field_caps", this);
  37. controller.registerHandler(POST, "/{index}/_field_caps", this);
  38. }
  39. @Override
  40. public String getName() {
  41. return "field_capabilities_action";
  42. }
  43. @Override
  44. public RestChannelConsumer prepareRequest(final RestRequest request,
  45. final NodeClient client) throws IOException {
  46. String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
  47. FieldCapabilitiesRequest fieldRequest = new FieldCapabilitiesRequest()
  48. .fields(Strings.splitStringByCommaToArray(request.param("fields")))
  49. .indices(indices);
  50. fieldRequest.indicesOptions(
  51. IndicesOptions.fromRequest(request, fieldRequest.indicesOptions()));
  52. return channel -> client.fieldCaps(fieldRequest, new RestToXContentListener<>(channel));
  53. }
  54. }