Search in sources :

Example 1 with GetFieldNamesRequest

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);
    }
}
Also used : GetFieldNamesRequest(io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesRequest) ZuliaIndexManager(io.zulia.server.index.ZuliaIndexManager) GetFieldNamesResponse(io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesResponse) Document(org.bson.Document) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get)

Aggregations

Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 GetFieldNamesRequest (io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesRequest)1 GetFieldNamesResponse (io.zulia.message.ZuliaServiceOuterClass.GetFieldNamesResponse)1 ZuliaIndexManager (io.zulia.server.index.ZuliaIndexManager)1 Document (org.bson.Document)1