Search in sources :

Example 1 with IdFilter

use of com.enonic.xp.query.filter.IdFilter in project xp by enonic.

the class CopyExecutor method createQuery.

private ElasticsearchQuery createQuery() {
    final IdFilter idFilter = IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(copyRequest.getNodeIds()).build();
    final QueryBuilder idFilterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(idFilter));
    QueryBuilder query = QueryBuilders.matchAllQuery();
    return ElasticsearchQuery.create().query(QueryBuilders.filteredQuery(query, idFilterBuilder)).addIndexName(copyRequest.getStorageSource().getStorageName().getName()).addIndexType(copyRequest.getStorageSource().getStorageType().getName()).size(copyRequest.getNodeIds().getSize()).batchSize(BATCH_SIZE).from(0).setReturnFields(ReturnFields.from(NodeIndexPath.SOURCE)).build();
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) FilterBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory)

Example 2 with IdFilter

use of com.enonic.xp.query.filter.IdFilter in project xp by enonic.

the class JsonToFilterMapperTest method ids_filter.

@Test
public void ids_filter() throws Exception {
    Map<String, Object> value = new HashMap<>();
    List<String> values = List.of("fisk", "ost", "løk");
    final HashMap<String, Object> valueFilter = new HashMap<>();
    valueFilter.put("values", values);
    value.put("ids", valueFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
    assertTrue(filters.get(0) instanceof IdFilter);
    assertEquals(3, ((IdFilter) filters.get(0)).getValues().size());
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

IdFilter (com.enonic.xp.query.filter.IdFilter)2 Filters (com.enonic.xp.query.filter.Filters)1 FilterBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory)1 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)1 HashMap (java.util.HashMap)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 Test (org.junit.jupiter.api.Test)1