When the index library has no data, the type of the field is date

Environmental Science:Windows 7
Version : elasticsearch 5.5

index mapping

   "createDate": {
      "type": "date",
      "store": "true",
      "format": "yyyy-MM-dd HH:mm:ss"
    }



GET /data/_search
{"from":0,"size":15,"query":{"bool":{"must":[]}},"sort":[{"createDate":{"order":"desc"}}]}

throws error

{
   "error": {
      "root_cause": [
         {
            "type": "query_shard_exception",
            "reason": "No mapping found for [createDate] in order to sort on",
            "index_uuid": "4ol3BN-HSMCRdXSeqQZ8wg",
            "index": "data"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "data",
            "node": "4TR60bJrS2-50jtZIh-zbw",
            "reason": {
               "type": "query_shard_exception",
               "reason": "No mapping found for [createDate] in order to sort on",
               "index_uuid": "4ol3BN-HSMCRdXSeqQZ8wg",
               "index": "data"
            }
         }
      ]
   },
   "status": 400
}

Please show what you get when running the following command:

GET data/_mapping

I would like to see the top of that file too
And do you have more than one type in the data index?

mapping index

PUT /data2
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ngram_analyzer": {
          "tokenizer": "ngram_tokenizer"
        }
      },
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "ngram",
          "min_gram": 1,
          "max_gram": 30
        }
      }
    }
  },
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "textMapping_no_analyzer_sore": {
            "match":"*_no_analyzer_sore",
            "mapping": {
              "type": "string",
              "store": "true",
              "index": "not_analyzed"
            }
          }
        },
        {
          "textMapping_sore_date": {
            "match":"*_sore_date",
            "mapping": {
              "type": "date",
              "store": "true",
              "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
            }
          }
        }
      ],
      "_all": {
        "enabled": false 
       },
      "properties": {
        "subjects": {
          "properties": {
            "count": {
              "type": "integer"
            },
            "name": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "language": {
            "type": "string",
            "index": "not_analyzed"
        },
        "classify": {
            "type": "string",
            "index": "not_analyzed"
        },
        "createDate": {
          "type": "date",
          "store": "true",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "updateDate": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "stage": {
          "type": "integer"
        }
      }
    }
  }
}

GET data2/_mapping

{
   "data2": {
      "mappings": {
         "_default_": {
            "_all": {
               "enabled": false
            },
            "dynamic_templates": [
               {
                  "textMapping_no_analyzer_sore": {
                     "match": "*_no_analyzer_sore",
                     "mapping": {
                        "index": "not_analyzed",
                        "store": "true",
                        "type": "string"
                     }
                  }
               },
               {
                  "textMapping_sore_date": {
                     "match": "*_sore_date",
                     "mapping": {
                        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
                        "store": "true",
                        "type": "date"
                     }
                  }
               }
            ],
            "properties": {
               "classify": {
                  "type": "keyword"
               },
               "createDate": {
                  "type": "date",
                  "store": true,
                  "format": "yyyy-MM-dd HH:mm:ss"
               },
               "language": {
                  "type": "keyword"
               },
               "stage": {
                  "type": "integer"
               },
               "subjects": {
                  "properties": {
                     "count": {
                        "type": "integer"
                     },
                     "name": {
                        "type": "keyword"
                     }
                  }
               },
               "updateDate": {
                  "type": "date",
                  "format": "yyyy-MM-dd HH:mm:ss"
               }
            }
         }
      }
   }
}

Now if you add some data in your new data2 index, your query doesn't work?

If I add data, it is not wrong to use the sort in the query. If there is no data, the sorting is wrong when the query is used.

Works perfectly well on my end. I suspect you have more than one type in your index and one of them doesn't have the createDate field. This is why I asked to see the full mapping of your original data index

GET /data2/_search
{"from":0,"size":15,"query":{"bool":{"must":[]}},"sort":[{"updateDate":{"order":"desc"}}]}

I made a mistake in changing a updateDate.

throws error

{
   "error": {
      "root_cause": [
         {
            "type": "query_shard_exception",
            "reason": "No mapping found for [updateDate] in order to sort on",
            "index_uuid": "-aEDUSRXR5etjh0y3VeLeA",
            "index": "data2"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "data2",
            "node": "4TR60bJrS2-50jtZIh-zbw",
            "reason": {
               "type": "query_shard_exception",
               "reason": "No mapping found for [updateDate] in order to sort on",
               "index_uuid": "-aEDUSRXR5etjh0y3VeLeA",
               "index": "data2"
            }
         }
      ]
   },
   "status": 400
}

I don't understand what you mean

You suspect that my createDate field does not exist. Well, it's also wrong to sort out the updateDate field.

GET /data2/_search
{"from":0,"size":15,"query":{"bool":{"must":[]}},"sort":[{"updateDate":{"order":"desc"}}]}

Can you understand what I mean

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

Well, thank you for your reminding.

Man, are you still there?

Read this and specifically the "Also be patient" part.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.