001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Benoit Delbosc 018 */ 019package org.nuxeo.elasticsearch.api; 020 021import java.util.List; 022 023import org.elasticsearch.action.search.SearchResponse; 024import org.nuxeo.ecm.core.api.DocumentModelList; 025import org.nuxeo.ecm.core.api.IterableQueryResult; 026import org.nuxeo.ecm.platform.query.api.Aggregate; 027import org.nuxeo.ecm.platform.query.api.Bucket; 028 029/** 030 * @since 6.0 031 */ 032public class EsResult { 033 private final DocumentModelList documents; 034 035 private final IterableQueryResult rows; 036 037 private final List<Aggregate<Bucket>> aggregates; 038 039 private final SearchResponse response; 040 041 public EsResult(DocumentModelList documents, List<Aggregate<Bucket>> aggregates, SearchResponse response) { 042 this.documents = documents; 043 this.rows = null; 044 this.aggregates = aggregates; 045 this.response = response; 046 } 047 048 public EsResult(IterableQueryResult rows, List<Aggregate<Bucket>> aggregates, SearchResponse response) { 049 this.documents = null; 050 this.rows = rows; 051 this.aggregates = aggregates; 052 this.response = response; 053 } 054 055 public EsResult(SearchResponse response) { 056 this.documents = null; 057 this.rows = null; 058 this.aggregates = null; 059 this.response = response; 060 } 061 062 /** 063 * Get the list of Nuxeo documents, this is populated when using a SELECT * clause, or when submitting esQuery. 064 * 065 * @return null if the query returns fields or if the onlyElasticsearchResponse option is set. 066 */ 067 public DocumentModelList getDocuments() { 068 return documents; 069 } 070 071 /** 072 * Iterator to use when selecting fields: SELECT ecm:uuid ... 073 * 074 * @since 7.2 075 * @return null if the query returns documents or if the onlyElasticsearchResponse option is set. 076 */ 077 public IterableQueryResult getRows() { 078 return rows; 079 } 080 081 /** 082 * Get the aggregates list or null if onlyElasticsearchResponse option is set. 083 */ 084 public List<Aggregate<Bucket>> getAggregates() { 085 return aggregates; 086 } 087 088 /** 089 * Returns the original Elasticsearch response. Use it at your own risk 090 * 091 * @since 7.3 092 */ 093 public SearchResponse getElasticsearchResponse() { 094 return response; 095 } 096}