Skrudox
Skrudox

Reputation: 939

Elasticsearch no mapping found for sort on field

No mapping found for field in order to sort on [created_at]

What does this message actually means? the field by itself created_at exists, should I rebuild the indexes? or is there a way to fix this error?

UPDATED :

{
   "query":{
      "bool":{
         "must":{
            "multi_match":{
               "query":"phone",
               "fields":[
                  "text"
               ],
               "minimum_should_match":"100%"
            }
         },
         "filter":{

         }
      }
   },
   "sort":[
      {
         "created_at":{
            "order":"desc"
         }
      }
   ]
}

Upvotes: 3

Views: 14579

Answers (5)

artin2
artin2

Reputation: 146

For me, I was querying Elasticsearch via Postman, and I knew the field existed and was being populated for all documents, but I was still seeing the No mapping found for field in order to sort on [<my_field>].

Turns out, I had an extra / in the GET request I was making. Removing the redundant / fixed the issue.

Upvotes: 0

sandy381
sandy381

Reputation: 1

What worked for me is that i created the field with mapping for index which had the field missing and did not push any data.So this eliminated the shards failed error.

Upvotes: 0

RameshN
RameshN

Reputation: 530

I faced the same issue with date fields. Problem is that created_at field not mapped properly.

We can solve this two ways

  1. Map created_at field with correct mappings with "type": "date"
  2. We can specify what to consider type of field when no mapping found in sort part like below

{
    "sort": [
        {
            "created_at": {
                "order": "desc",
                "unmapped_type": "date"
            }
        }
    ]
}

I hope this may help you.

Upvotes: 7

Vielen Danke
Vielen Danke

Reputation: 187

It could be also if your data of this field is empty.

It helped for me, because I used to use searching in empty data, and Elastic has thrown this exception. After I fulfilled with Data, everything started to work fine.

Upvotes: 2

Muhammad Zubair Saleem
Muhammad Zubair Saleem

Reputation: 517

it is because your datetime filed named created_at is not mapped correctly in your index that is the reason you just have that field as a string and you can't sort on that field you need to put mapping first before indexing data. for further read about mappings and how you can create a template for that to auto-create mappings for you.

for sorting this will be helpful for you.

Upvotes: 1

Related Questions