Skip to content

Commit

Permalink
opensearch-project#37 Changing query and event timestamp formats to s…
Browse files Browse the repository at this point in the history
…trict_date_time.

Signed-off-by: jzonthemtn <jeff.zemerick@mtnfog.com>
  • Loading branch information
jzonthemtn committed Oct 23, 2024
1 parent 1e92b6d commit 9a52977
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/opensearch/ubi/QueryRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

/**
* A query received by OpenSearch.
*/
public class QueryRequest {

private final long timestamp;
private final String timestamp;
private final String queryId;
private final String clientId;
private final String userQuery;
Expand All @@ -40,7 +43,8 @@ public class QueryRequest {
public QueryRequest(final String queryId, final String userQuery, final String clientId, final String query,
final Map<String, String> queryAttributes, final QueryResponse queryResponse) {

this.timestamp = System.currentTimeMillis();
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault());
this.timestamp = sdf.format(new Date());
this.queryId = queryId;
this.clientId = clientId;
this.userQuery = userQuery;
Expand Down Expand Up @@ -79,7 +83,7 @@ public Map<String, String> getQueryAttributes() {
* Gets the timestamp.
* @return The timestamp.
*/
public long getTimestamp() {
public String getTimestamp() {
return timestamp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/events-mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"message_type": { "type": "keyword", "ignore_above": 100 },
"timestamp": {
"type": "date",
"format":"rfc3339_lenient||epoch_millis",
"format":"strict_date_time",
"ignore_malformed": true,
"doc_values": true
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/queries-mapping.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dynamic": false,
"properties": {
"timestamp": { "type": "date" },
"timestamp": { "type": "date", "format": "strict_date_time" },
"query_id": { "type": "keyword", "ignore_above": 100 },
"query": { "type": "text" },
"query_response_id": { "type": "keyword", "ignore_above": 100 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
index: ecommerce
body:
mappings:
{ "properties": { "category": { "type": "text" } } }
{ "properties": { "category": { "type": "text" }, "timestamp": { "type": "date", "format": "strict_date_time" } } }

- match: { acknowledged: true }
- match: { index: "ecommerce"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
index: ecommerce1
body:
mappings:
{ "properties": { "category": { "type": "text" } } }
{ "properties": { "category": { "type": "text" }, "timestamp": { "type": "date", "format": "strict_date_time" } } }

- match: { acknowledged: true }
- match: { index: "ecommerce1"}
Expand Down

0 comments on commit 9a52977

Please sign in to comment.