Elasticsearch cannot access keys although they are available

Hello,

recently I have been running into an issue with elastic.

I have a single node Elasticsearch-Container running in Docker.

Sometimes it seems that Elasticsearch is not running as it should so I have tried to debug it using kibana.

In case (case 1) it runs properly, the following queue

GET /trend_meta/_search

{
    "query": {
        "constant_score": {
            "filter": {
                "term": {
                    "id": "trend9d27baa7-7dbe-4448-891a-814cab9e805f"
                }
            }
        }
    }
}

results in this response:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
        },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
            },
        "max_score": 1,
        "hits": [
            {
                "_index": "trend_meta",
                "_id": "trend9d27baa7-7dbe-4448-891a-814cab9e805f",
                "_score": 1,
                "_source": {
                    "id": "trend9d27baa7-7dbe-4448-891a-814cab9e805f",
                    "liveTime": 60,
                    "legend": {
                        "legendType": "Top",
                        "column": 3
                        },
                    "labelIt": [
                        {
                        "languageTag": "en",
                        "text": "Trend 01"
                        }
                    ]
                }
            }
        ]
    }
}

if it is not working properly (case 2), the response is:

{
"took": 0,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
    },
"hits": {
    "total": {
        "value": 0,
        "relation": "eq"
        },
    "max_score": null,
    "hits": []
    }
}

If I would use "_id": "trend9d27baa7-7dbe-4448-891a-814cab9e805f" instead of "id": "trend9d27baa7-7dbe-4448-891a-814cab9e805f" in the search query, the response would be as expected (like the response of case 1), no matter if the Elasticsearch is running well or with issues.

The key _id is the id given from Elasticsearch. The key id is a key I defined.

GET /_template/trend_meta

response:

{
"trend_meta": {
    "order": 0,
    "index_patterns": [
        "trend_meta"
        ],
    "settings": {},
    "mappings": {
        "properties": {
            "id": {
                "type": "keyword"
                }
            }
        }, "aliases": {}
    }
}

My problem is that my code does not allow me to use the key _id instead of id. Somehow there seem to be cases when the key id is available but not accessible.

Have you run into the same issue before and have you been able solve it?

Welcome!

May be the document is not searchable yet because the index has not been refreshed?

You can call:

POST trend_meta/_refresh

Before searching and check if this works.

If not, can you run:

GET trend_meta/_doc/trend9d27baa7-7dbe-4448-891a-814cab9e805f

Where trend9d27baa7-7dbe-4448-891a-814cab9e805f is the id you are searching for.

1 Like