Getting error "No mapping found for [logdata.timestamp] in order to sort on"

Viewed 986

Getting error No mapping found for [logdata.timestamp] in order to sort on"

{
            "dynamic": "false",
            "_meta": {
                "version": 2,
                "updateTimeInMs": 1607537203813
            },
            "properties": {
                "log": {
                    "properties": {
                        "logid": {
                            "type": "keyword"
                        },
                        "logdata": {
                            "type": "text",
                            "index": false
                        },
                        "timestamp": {
                            "type": "date"
                        },
                        "version": {
                            "type": "integer",
                            "index": false,
                            "doc_values": false
                        }
                    }
                }
            }
        }

and i am using to fetch the results Note:- Fields logid and timestamps are indexed

{
    "from": 0,
    "size": 1000,
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "logid": {
                            "value": "1",
                            "boost": 1.0
                        }
                    }
                },
                {
                    "range": {
                        "timestamp": {
                            "from": 1607212800,
                            "to": 1607299200,
                            "include_lower": true,
                            "include_upper": true,
                            "boost": 1.0
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    },
    "sort": [
        {
            "timestamp": {
                "order": "asc"
            }
        }
    ]
}
1 Answers

Based on the mapping you have provided, you should use log.timestamp and log.logid field, the modified search query will be :

{
  "from": 0,
  "size": 1000,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "log.logid": {
              "value": "1",
              "boost": 1.0
            }
          }
        },
        {
          "range": {
            "log.timestamp": {
              "from": 1607212800,
              "to": 1607299200,
              "include_lower": true,
              "include_upper": true,
              "boost": 1.0
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1.0
    }
  },
  "sort": [
    {
      "log.timestamp": {           <-- note this
        "order": "asc"
      }
    }
  ]
}
Related