sergehuber commented on code in PR #715: URL: https://github.com/apache/unomi/pull/715#discussion_r2428139919
########## persistence-opensearch/conditions/src/main/java/org/apache/unomi/persistence/opensearch/querybuilders/advanced/IdsConditionOSQueryBuilder.java: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.unomi.persistence.opensearch.conditions; + +import org.apache.unomi.api.conditions.Condition; +import org.apache.unomi.persistence.opensearch.ConditionOSQueryBuilder; +import org.apache.unomi.persistence.opensearch.ConditionOSQueryBuilderDispatcher; +import org.opensearch.client.opensearch._types.query_dsl.Query; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +public class IdsConditionOSQueryBuilder implements ConditionOSQueryBuilder { + + private int maximumIdsQueryCount = 5000; + + public void setMaximumIdsQueryCount(int maximumIdsQueryCount) { + this.maximumIdsQueryCount = maximumIdsQueryCount; + } + + @Override + public Query buildQuery(Condition condition, Map<String, Object> context, ConditionOSQueryBuilderDispatcher dispatcher) { + Collection<String> ids = (Collection<String>) condition.getParameter("ids"); + Boolean match = (Boolean) condition.getParameter("match"); + + if (ids.size() > maximumIdsQueryCount) { + // Avoid building too big ids query - throw exception instead + throw new UnsupportedOperationException("Too many profiles"); Review Comment: I've improved the exception message to include the limit, I also did the change in the ElasticSearch implementation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
