No mapping found for [timestamp] in order to sort on

I have developed a small node.js server, which will use the elasticsearch npm module to get the latest JSON document based on timestamp.

Here is the code for it,

let express = require('express');
let app = express();
let elasticsearch = require('elasticsearch');

app.listen(3000, function() {
    console.log('Example app listening on port 3000!');
});

let client = new elasticsearch.Client({
    host: ['http://localhost:9200']
});

client.ping({
    requestTimeout: 30000,
}, function(error) {
    if (error) {
        console.error('elasticsearch cluster is down!');
    } else {
        console.log('Everything is ok');
    }
});

async function getResponse() {

    const response = await client.search({
        index: 'weather',
        type: 'doc',
        body: {
            sort: [{ "timestamp": { "order": "desc" } }],
            size: 1,
            query: { match_all: {} }
        }
    });

    console.log(response);

}

getResponse();

When In run the code, I get an error like this,

(node:11372) UnhandledPromiseRejectionWarning: Error: [query_shard_exception] No mapping found for [timestamp] in order to sort on, with { index_uuid="j-TaPYgLRhuYyiJJjg1tYg" & index="weather" }

Is there anything wrong with the search config? Would appreciate if anybody could help. Thanks!

What is the mapping of your weather index?

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