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