k.explorer
k.explorer

Reputation: 321

elastic search "multi Match" query failing while search on all existing fields of index

i have a scenario of using "multi_match" query to search on all the fields of a index, but while doing so i am getting an error as mentioned below. According to my preliminary investigation i suppose the issue could be because of field of type date present in the index, and ES is unable to parse my search string to date and do a comparison.

Note :All the fields present in the index are created using dynamic template , so i couldn't know the name of the fields and because of that i am running my query on all fields.

Any help is appreciated.

Query:

GET /indexname/_search
{
  "query": {
"bool" : {
"should" : [
{
"multi_match" : {
"query" : "mazda",
"fields" : [
"analyzedFields.*"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_transpositions" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}

error :

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]: [failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "kapturedate.service_information.ja_jp",
        "node": "mpVDNnyiRJy-bLvz3bDUuA",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"should\" : [\n      {\n        \"multi_match\" : {\n          \"query\" : \"mazda\",\n          \"fields\" : [\n            \"analyzedFields.STARTDATE.actualdate^1.0\"\n          ],\n          \"type\" : \"best_fields\",\n          \"operator\" : \"OR\",\n          \"slop\" : 0,\n          \"prefix_length\" : 0,\n          \"max_expansions\" : 50,\n          \"zero_terms_query\" : \"NONE\",\n          \"auto_generate_synonyms_phrase_query\" : true,\n          \"fuzzy_transpositions\" : true,\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "EqzcPvzUQcy63TIzYi_N6g",
          "index": "kapturedate.service_information.ja_jp",
          "caused_by": {
            "type": "parse_exception",
            "reason": "failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]: [failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]]",
            "caused_by": {
              "type": "illegal_argument_exception",
              "reason": "failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]",
              "caused_by": {
                "type": "date_time_parse_exception",
                "reason": "Failed to parse with all enclosed parsers"
              }
            }
          }
        }
      }
    ],
    "caused_by": {
      "type": "parse_exception",
      "reason": "failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]: [failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]]",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "failed to parse date field [mazda] with format [strict_date_optional_time||yyyy-mm-dd||yyyy-mm-dd HH:mm:ss||yyyy/mm/dd||mm/dd/yyyy HH:mm||mm/dd/yyyy HH:mm:ss]",
        "caused_by": {
          "type": "date_time_parse_exception",
          "reason": "Failed to parse with all enclosed parsers"
        }
      }
    }
  },
  "status": 400
}

Upvotes: 2

Views: 973

Answers (1)

Joe - Check out my books
Joe - Check out my books

Reputation: 16895

If you really don't know what fields you've got and/or you cannot retrieve this information before executing the query, I'd suggest adjusting your dynamic templates such that all fields are indexed as text by default and then if the system encounters a date-like field, it'll create another field property in the form of, say, my_datelike_field.as_date.

That way, all your fields are now searchable using multi_match and you can still perform optimized date range/histograms. The same applies to numbers, geo points, etc. This answer should get you started.

Upvotes: 2

Related Questions