TeamZ
TeamZ

Reputation: 361

ElasticSearch: Multi_fields parameter not working

I have a multi fields parameter "startTime", below is the mapping

"startTime" : {
      "type" : "text",
      "fields" : {
        "keyword" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "raw" : {
          "type" : "date",
          "format" : "dd-MM-yyyy HH:mm:ss||dd-MM-yyyy||hour_minute_second"
        }
      }
    }

i inserted few documents

{    
  "orgId" => "backendorg",
  "startTime" => "01-01-1980 06:32:51"
}
{
  "orgId" => "backendorg",
  "startTime" => "01-01-1980 06:35:51"
}
{          
  "orgId" => "backendorg",
  "startTime" => "01-01-1980 06:39:51"
}

when i am trying to filter startTime based on below query it is returning empty result

{
"query": {
"bool": {
  "must": [
    {
      "term": {
        "orgId": {
          "value": "backendorg",
          "boost": 1
        }
      }
    },
    {
      "bool": {
        "should": [
          {
            "range": {
              "startTime": {
                "from": "01-01-1980 06:32:51",
                "to": "01-01-1980 06:39:51",
                "include_lower": true,
                "include_upper": true,
                "boost": 1
                }
              }
            }
          ]
        }
      }
    ]
  }
 }
}

could someone tell me what is wrong with my query or mapping.

Upvotes: 0

Views: 32

Answers (1)

Val
Val

Reputation: 217474

Since your date field is a sub-field called startTime.raw you need to use it in your range query

      {
        "range": {
          "startTime.raw": {                        <----- change this
            "from": "01-01-1980 06:32:51",
            "to": "01-01-1980 06:39:51",
            "include_lower": true,
            "include_upper": true,
            "boost": 1
            }
          }
        }
      ]

Upvotes: 1

Related Questions