here is elasticsearch official website about terms: https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-terms-query.html
As we can see, if we want
The terms lookup mechanism is basically a built-in optimization to not have to make two queries to JOIN two indices, i.e. one in index A to get the ids to lookup and a second to fetch the documents with those ids in index B.
In contrary to SQL, such a JOIN can only work on the id
field since this is the only way to uniquely retrieve a document from Elasticsearch via a GET call, which is exactly what Elasticsearch will do in the terms
lookup.
So to answer your question, the terms lookup mechanism will not work on any other field than the id
field since the first document to be retrieved must be unique. In your case, ES would not know how to fetch the document for the user with name
Jane
since name
is just a field present in the user document, but in no way a unique identifier for user Jane
.