Hello there,
we have an application which allows our customer to upload and index almost any data. We seem to have an issue, if we have a property whose type is "Text", but the input data can be interpreted as a datetime.
First of all, let me show you a part of our mapping, which was received via Kibana Get index/_mappings:
"fi@Date": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}}}
fi@Date is our property and its type is text. Therefore any string can be used! Our index currently has 2 entries, which look like this (once again partially reduced):
"_index": "cxcrgygrgemj9cjaofexlq_v1",
"_source": {
"filename": "DemoFile01",
"fi@Date": "2018-10-31T08:25:52",
Second entry:
"_index": "cxcrgygrgemj9cjaofexlq_v1",
"_source": {
"filename": "DemoFile02",
"fi@Date": "Abc8-10-31T08:25:52"
Note that the first entry has "fi@Date": "2018-10-31T08:25:52",. The right hand side is a datetime representation, but the property fi@Date is defined as a text.
This causes currently two problems:
-
Using the NEST high level client, we create a request of type
SearchRequest<Dictionary<string, object>>
The key of the result dictionary is the name of the property (e.g. "fi@Date") and the value its according value. The NEST client converts this value to DateTime. So we lose some information of the original string (the T is lost). However, if we perform a text search on this property, the correct string is vital. E.g. a TermsQuery does only hit, if we provide the exact string "2018-10-31T08:25:52".
The second entry "Abc8-10-31T08:25:52" is returned as a normal string and does not yield any problems. The NEST client seems to convert entries based on the result, not on the defined mapping. Is there a way to circumvent this behaviour? -
Using the following query in Kibana causes an exception. The same happens with a QueryStringQuery in the NEST Client.
GET cxcrgygrgemj9cjaofexlq/_search { "query": { "query_string" : { "query": "2018-10-31T08:25:52", "default_field": "fi@Date", "default_operator": "or" } } }
It gives
"reason": "Failed to parse query [2018-10-31T08:25:52]",
"reason": "Cannot parse '2018-10-31T08:25:52': Encountered " ":" ": "" at line 1, column 16.\r\nWas expecting one of:\r\n \r\n ...\r\n ...\r\n ...\r\n "+" ...\r\n "-" ...\r\n ...\r\n "(" ...\r\n "" ...\r\n "^" ...\r\n ...\r\n ...\r\n <FUZZY_SLOP> ...\r\n ...\r\n ...\r\n ...\r\n "[" ...\r\n "{" ...\r\n ...\r\n ",
"caused_by": {
"type": "parse_exception",
"reason": "Encountered " ":" ": "" at line 1, column 16.\r\nWas expecting one of:\r\n \r\n ...\r\n ...\r\n ...\r\n "+" ...\r\n "-" ...\r\n ...\r\n "(" ...\r\n "" ...\r\n "^" ...\r\n ...\r\n ...\r\n <FUZZY_SLOP> ...\r\n ...\r\n ...\r\n ...\r\n "[" ...\r\n "{" ...\r\n ...\r\n "
}
Edit: There is no error, if we change slightly change the query, so it does no longer match a datetime e.g. "2018-10-31T08:2552" (removed colon). /Edit
Any ideas? Is this an ElasticSearch Bug? Can I do something to prevent both behaviours?
Version Info
NEST 5.6.5
ElasticSearch.Net 5.6.5
Elastic Search on Server 5.5
Kind regards,
Jörg