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

**URL:** <https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195>\
**Category:** Elasticsearch\
**Created:** [January 5, 2018, 3:56am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195 "2018-01-05T03:56:32Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 3:56am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/1 "2018-01-05T03:56:32Z")

</div>

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
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 5, 2018, 5:05am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/2 "2018-01-05T05:05:47Z")

</div>

Please show what you get when running the following command:

`GET data/_mapping`

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 5:09am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/3 "2018-01-05T05:09:50Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/b/7b3c59410a6eb350f82974ab56083961571bd484.png)

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 5, 2018, 5:14am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/4 "2018-01-05T05:14:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 6:06am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/5 "2018-01-05T06:06:46Z")

</div>

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"
               }
            }
         }
      }
   }
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 5, 2018, 6:08am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/6 "2018-01-05T06:08:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 6:10am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/7 "2018-01-05T06:10:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 5, 2018, 6:17am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/8 "2018-01-05T06:17:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 6:23am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/9 "2018-01-05T06:23:02Z")

</div>

```
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
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 5, 2018, 6:25am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/10 "2018-01-05T06:25:56Z")

</div>

> [@hubiao](#):
>
> I made a mistake in changing a updateDate.

I don't understand what you mean

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 6:27am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/11 "2018-01-05T06:27:34Z")

</div>

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"}}]}
```

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 6:49am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/12 "2018-01-05T06:49:00Z")

</div>

Can you understand what I mean

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 5, 2018, 7:05am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/13 "2018-01-05T07:05:51Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```
````

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 8:10am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/15 "2018-01-05T08:10:11Z")

</div>

Well, thank you for your reminding.

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [January 5, 2018, 8:23am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/16 "2018-01-05T08:23:22Z")

</div>

Man, are you still there？

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 5, 2018, 8:42am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/17 "2018-01-05T08:42:08Z")

</div>

Read [this](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and specifically the "Also be patient" part.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 2, 2018, 8:42am UTC](https://discuss.elastic.co/t/when-the-index-library-has-no-data-the-type-of-the-field-is-date/114195/18 "2018-02-02T08:42:11Z")

</div>

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