use of io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesRequest in project zuliasearch by zuliaio.
the class FieldsController method get.
@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(ZuliaConstants.INDEX) final String indexName, @QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty) {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
GetFieldNamesRequest fieldNamesRequest = GetFieldNamesRequest.newBuilder().setIndexName(indexName).build();
GetFieldNamesResponse fieldNamesResponse;
try {
fieldNamesResponse = indexManager.getFieldNames(fieldNamesRequest);
Document mongoDocument = new Document();
mongoDocument.put("index", indexName);
mongoDocument.put("fields", fieldNamesResponse.getFieldNameList());
String docString = mongoDocument.toJson();
if (pretty) {
docString = JsonWriter.formatJson(docString);
}
return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
} catch (Exception e) {
return HttpResponse.ok("Failed to fetch fields for index <" + indexName + ">: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
}
}
Aggregations