can terms lookup mechanism query by other field but id?

前端 未结 2 637
难免孤独
难免孤独 2021-01-20 04:35

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

2条回答
  •  灰色年华
    2021-01-20 04:43

    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.

提交回复
热议问题