如何在 COMOS v4 同步 api container.queryItems() 中获取 eTag 值

问题描述

在使用 comsos v4 java async apis 时遇到这个问题。 我看到 eTag 值,如果使用了 container.readItem(),但不是在 container.queryItems() 中。 当我检查 queryItem 响应中的响应标头数据时,eTag 为空。 谁能告诉我,这是 cosmos API 错误还是我遗漏了什么?

        responseDocuments
                .byPage(1)
                .log()
                .flatMap(person-> {
                    person.getResults().stream().forEach(document-> {
                        if(document.get("optInStatus") != null) {
                        } else {
                            list.add(gson.fromJson(gson.toJson(document,LinkedHashMap.class),Person.class));
                        }

                    });
                    System.out.println(person.getResponseHeaders().get("etag")); // coming as null
                    System.out.println(person.getContinuationToken());
                    System.out.println(person.getResponseHeaders().toString());
                    return Flux.empty();
                })
                .blockLast();

解决方法

如果是 cosmos API 错误还是我遗漏了什么?

您没有遗漏任何内容,我认为这不是错误。我尝试了 REST API。它也不会在响应标头中提供 _eTag 属性。如果您在查询项目时需要该系统属性,您可以将该属性添加到您的 POJO。