GithubHelp home page GithubHelp logo

luces's Introduction

Luces

A library to convert Lucene documents to JSON for Elasticsearch consumption

License: Apache 2.0

Build Status Coverage Status

Dependencies:

  • Java 8
  • gson 2.3.1
  • lucene-core 3.6.1
  • junit 3.8.1
  • slf4j 1.7.5

Usage:

The library can be used like so:

Luces lucesConverter = new Luces(org.apache.lucene.util.Version.LUCENE_36)
JsonElement jsonDoc = lucesConverter.documentToJSON(Document doc);

Where doc is a populated Lucene document. A JsonObject will be returned that can be sent to Elasticsearch. For testing purposes, you can also pass a boolean to pretty print the output:

String jsonBlob = lucesConverter.documentToJSONStringified(Document doc, true);

You can also specify an elasticsearch mapping JSON blob, which will enable any string values that are supposed to be integers, floats, etc. into their correct types For example, a mapping like:

{
  "user": {
    "properties": {
      "name": {
        "type": "string"
      },
      "id": {
        "type": "integer"
      }
    }
  }
}

can be added to the converter this way, as a JsonObject:

lucesConverter.mapping("user", mappingJsonObject)

where "user" is the type in Elasticsearch.

When using a mapping file, empty values will not be parsed correctly, so you can specify if you want empty values replaced with the defaults for the type:

lucesConverter.useDefaultsForEmpty(true);

Otherwise, it defaults to false, and will throw a NumberFormatException when a value is empty. Keep in mind that invalid values (like 123abc in an integer field) will still throw parsing errors regardless of the flag

##Options:

lucesConverter.useDefaultsForEmpty(bool);

If true, uses the default value for a primitive if the string is empty (0, 0.0, false). Setting to true will set useNullForEmpty to false

lucesConverter.useNullForEmpty(bool);

If true, uses null for an empty string value. Setting to true will set useDefaultsForEmpty to false.

lucesConverter.throwErrorIfMappingIsNull(bool);

Throws an error if the mapping is set to null, or if trying to convert a document without specifying a type and mapping. Defaults to true

TODO:

  • Handle mappings with hierarchical levels to type determination

luces's People

Contributors

bdharrington7 avatar dougschroeder avatar jigarjoshi avatar yurikap avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.