I wish I could, but currently prohibited. However, I can point you to some 
very good Java libraries:

The CSV parser supplied by the Apache project works well:

https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html

You can override the delimiter using the static CSVFormat newFormat(char 
delimiter) method which creates a new CSV format with the specified 
delimiter:

https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVFormat.html

Then use the XContentBuilder cb = jsonBuilder() method call to create a 
content builder to convert your records to single-line JSON.

For example, the action and meta data object I use is based on the 
following ENUM and toString method to emit as JSON. I've left out the parst 
that I use in other custom libraries that allow Java code to easily set up 
this information, and also to set this from a search response or a 
get-by-id response:

  public enum OpType
  {
    CREATE,
    INDEX,
    DELETE
  }

  @Override
  public String toString()
  {
    try
    {
      XContentBuilder cb = jsonBuilder();
      cb.startObject();

      cb.field(opType.toString().toLowerCase());
      cb.startObject();

      cb.field("_index", index);
      cb.field("_type", type);
      if (id != null)
        cb.field("_id", id);

      if (version > 0)
      {
        cb.field("_version", version);
        if (versionType == VersionType.EXTERNAL)
          cb.field("_version_type", "external");
      }

      if (ttl != null)
        cb.field("_ttl", ttl);

      cb.endObject();

      cb.endObject();
      return cb.string();
    }
    catch (IOException e)
    {
      return ("null");
    }

  }

  /* Operation type (action): "create" or "index" or "delete" */
  private OpType      opType      = OpType.INDEX;

  /* Metadata that this object supports */
  private String      index       = null;
  private String      type        = null;
  private String      id          = null;
  private long        version     = 0;
  private VersionType versionType = VersionType.INTERNAL;
  private TimeValue   ttl         = null;

And the actual data line that would follow is similarly constructed using 
the content builder.

I wish I could help you more.

Brian


On Wednesday, January 7, 2015 10:41:26 AM UTC-5, Gopimanikandan Sengodan 
wrote:
>
> Thank you brian.  Let me change it accodingly as per your suggestion.  
> Could it possible to share the bulk load client and csv to json converter?
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/9d46f746-04c6-48fe-93bc-a0c8612539ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to