Can't get document by id


(Fabiocatalao) #1

Hi,

I'm being unable to get documents that I index using Java API from the index by id. I'm using the following code to prepare the index:

IndexRequest indexRequest = new IndexRequest(myindex, mytype, myid)
                    .source(mysource.toString())
                    .routing(myrootingkey);

When I try to get a document I receive an empty found.

GET mynode.:9200/myindex/1/211535
    {
        "_index": "myindex",
        "_type": "1",
        "_id": "211535",
        "found": false
    }

I've also tried to manually add a document and this way I'm able to get the document.

I've searched for it and found some users with the same problem but most of them use older elasticsearch versions. I'm currently on 5.5.4 so the problem could not be the same.
I've found some information that the problem could be related to the rooting key but I couldn't find any official information about this bug/feature or how does it affect it.

Can someone explain to me what I'm doing wrong and why can't I make it work the way I'm doing it?

Thanks


(Christian Dahlqvist) #2

If you index with a routing key, you need to query using it too.


(Fabiocatalao) #3

Thank you.
I've successfully made it work adding ?routing=routing_key arg.
I'm going to rethink the way we are using routing as it has other disadvantages that were not taken into account at the time it was implemented.


(system) #4

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