ES data-mysql processing data import processing of date types

Source: Internet
Author: User
Tags object object

With ES of small partners, I believe we have encountered mapping processing date type of data headache problem it.

No more headaches, I'll give you a solution:

1. Maping is defined as:

{
"Mappings": {
"Carecustomerlog_type_all": {
"Properties": {
"ID": {
' type ': ' Long '
},
"Applyrate": {
' type ': ' Double '
},
"Preapplyrate": {
' type ': ' Double '
},
' TYPE ': {
' type ': ' Long '
},
"CDATE": {
' type ': ' Long '
},
"Carecustomid": {
' type ': ' Long '
},
"Careaccountid": {
' type ': ' Long '
},
"Watenum": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CustomerID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"OrderID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CustomerName": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Content": {
' Type ': ' String ',
"Index": "Not_analyzed"
}
}
},
"Careaccountin_type_all": {
"Properties": {
"id": {
' type ': ' Long '
},
"CustomerID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"GroupID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"AccountType": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Rate": {
' type ': ' Double '
},
"Amount": {
' type ': ' Double '
},
"Fee": {
' type ': ' Double '
},
"Sellerid": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Sellername": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"State": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CustomerName": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CreateDate": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"GroupName": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Adviserid": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Advisername": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"OrderGroupID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Ordergroupname": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Comm": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Watenum": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Appkey": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Paytime": {
' type ': ' Long '
}
}
},
"Carecustomerlog_type_funddetails": {
"Properties": {
"ID": {
' type ': ' Long '
},
"CDATE": {
' type ': ' Long '
},
"OrderID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Preapplyrate": {
' type ': ' Double '
},
"Applyrate": {
' type ': ' Double '
},
"Content": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
' TYPE ': {
' type ': ' Long '
},
"Careaccountid": {
' type ': ' Long '
},
"Watenum": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CustomerID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"GroupID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"AccountType": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Rate": {
' type ': ' Double '
},
"Amount": {
' type ': ' Double '
},
"Fee": {
' type ': ' Double '
},
"Sellerid": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Sellername": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"State": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CustomerName": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"CreateDate": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"GroupName": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Adviserid": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Advisername": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"OrderGroupID": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Ordergroupname": {
' Type ': ' String ',
"Index": "Not_analyzed"
},
"Paytime": {
' type ': ' Long '
}
}
}
}
}

In mapping, the date type data is defined in ES as a long type.

When executing code, use the MySQL function Unix_timestamp (cai.paytime) to get the second data of the date, inserted into ES

public static apiresult<string> Save (string index, String type, String idname, Jsonarray Jsonarray)
{
Bulkrequestbuilder bulkrequest = Client.preparebulk (). Setrefresh (True);

for (Iterator localiterator = Jsonarray.iterator (); Localiterator.hasnext ();) {Object object = Localiterator.next ();
Jsonobject JSON = Stringutils.isjsonobject (object);
String idvalue = json.optstring (idname);
if (Stringutils.isblank (idvalue)) {
Idvalue = Idname;
}

if (Stringutils.isblank (idname)) {
Indexrequestbuilder LRB = Client.prepareindex (index, type). SetSource (Json.tostring ());
Bulkrequest.add (LRB);
}
Else
{
Indexrequestbuilder LRB = Client.prepareindex (index, type, idvalue). SetSource (Json.tostring ());
Bulkrequest.add (LRB);
}
}

Bulkresponse bulkresponse = null;
try {
Bulkresponse = (bulkresponse) bulkrequest.execute (). Actionget ();
}
catch (Exception e) {
E.printstacktrace ();
}
if (Bulkresponse.hasfailures ())
{
System.out.println (Bulkresponse.getitems (). toString ());
return new Apiresult (500, "Save ES failed!");
}
Bulkrequest = Client.preparebulk ();
return new Apiresult (200, "Save ES Success!");
}

, do add, remind es default to set the word breaker, before adding, should first define mapping, in the execution of Add.

You can then perform a SELECT, update, delete operation.

ES data-mysql processing data import processing of date types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.