首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch 7中的运算符IN

ElasticSearch 7中的运算符IN
EN

Stack Overflow用户
提问于 2020-02-20 15:28:35
回答 1查看 126关注 0票数 0

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

代码语言:javascript
复制
@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;
}

储存库:

代码语言:javascript
复制
@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);

我的弹性索引:

代码语言:javascript
复制
{
  "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:

弹性搜索异常[type=parsing_exception,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-高级别-client-7。4.0.jar:7.4.0在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-高级-客户-7.4.0.jar:7.4.0

我从以下链接的文档中获得了一个查询:https://docs.spring.io/spring-data/elasticsearch/docs/4.0.x/reference/html/#elasticsearch.query-methods

我怎样才能纠正错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-21 07:58:17

“谢谢,”瓦尔,你引导我走上了正确的道路。问题是我是如何形成收藏的。我的问题中没有提到这一点。我贴出了修正后的代码:

代码语言:javascript
复制
List<String> aoGuidList = new ArrayList<>();
it.getParts().forEach(itt -> {
    aoGuidList.add("\"" + itt.getAoGuid() + "\"");
});

queryHouseService.search(aoGuidList);

现在我的存储库:

代码语言:javascript
复制
@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“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60323342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档