ElasticSearch 7 中的运算符 IN

Operator IN in ElasticSearch 7

我有一个关于 Spring 数据 elasticSearch 的项目。 型号:

@Document(indexName = "house", createIndex = false)
public class House {
    @Id
    private String id;
    private String aoGuid;
    private String buildNum;
    private String houseGuid;
    private String houseId;
    private String houseNum;
    private String postalCode;
    private String regionCode;
}

存储库:

@Query("{\n" +
        "  \"bool\": {\n" +
        "    \"must\": [\n" +
        "      {\n" +
        "        \"bool\": {\n" +
        "          \"must\": [\n" +
        "            {\n" +
        "              \"terms\": {\n" +
        "                \"aoGuid\": \"[?0]\"\n" +
        "              }\n" +
        "            }\n" +
        "          ]\n" +
        "        }\n" +
        "      }\n" +
        "    ]\n" +
        "  }\n" +
        "}")
List<House> findByAoGuidIn(Collection<String> aoGuid);

我在 Elastic 中的索引:

{
  "house": {
    "aliases": {},
    "mappings": {
      "properties": {
        "_class": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "aoGuid": {
          "type": "keyword"
        },
        "buildNum": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "houseGuid": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "houseId": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "houseNum": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "postalCode": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "regionCode": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "search": {
          "slowlog": {
            "threshold": {
              "query": {
                "info": "1ms"
              }
            }
          }
        },
        "number_of_shards": "1",
        "provided_name": "house",
        "creation_date": "1582210642568",
        "number_of_replicas": "1",
        "uuid": "c43T1LthTH6LhTphjZ-Ulw",
        "version": {
          "created": "7040099"
        }
      }
    }
  }
}

当我调用 findByAoGuidIn 方法时,出现错误:

org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=parsing_exception, reason=[terms] query does not support [aoGuid]] at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) ~[elasticsearch-7.4.0.jar:7.4.0] at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1727) ~[elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0] at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1704) ~[elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0] at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1467) ~[elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0] at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424) ~[elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0] at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394) ~[elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0]

我在 link 的文档中查询了:https://docs.spring.io/spring-data/elasticsearch/docs/4.0.x/reference/html/#elasticsearch.query-methods

如何修复错误?

谢谢@Val,你引导我走上了正确的思维道路。 问题是我如何形成集合。我没有在我的问题中提供这个。 我post更正后的代码:

List<String> aoGuidList = new ArrayList<>();
it.getParts().forEach(itt -> {
    aoGuidList.add("\"" + itt.getAoGuid() + "\"");
});

queryHouseService.search(aoGuidList);

现在我的存储库:

@Query("{\n" +
        "  \"bool\": {\n" +
        "    \"must\": [\n" +
        "      {\n" +
        "        \"bool\": {\n" +
        "          \"must\": [\n" +
        "            {\n" +
        "              \"terms\": {\n" +
        "                \"aoGuid\": ?0\n" +
        "              }\n" +
        "            }\n" +
        "          ]\n" +
        "        }\n" +
        "      }\n" +
        "    ]\n" +
        "  }\n" +
        "}")
List<House> findByAoGuidIn(Collection<String> aoGuid);

确实,我必须确保我在请求中的集合符合模式 ["val1"、"val2"]。在我的错误版本中,我得到了以下形式的集合:[val1, val2] 或 ["val1, val2"]