use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class AggregationIntegrationTests method before.
@BeforeEach
public void before() {
indexOperations = operations.indexOps(ArticleEntity.class);
IndexInitializer.init(indexOperations);
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10).buildIndex();
IndexQuery article2 = new ArticleEntityBuilder("2").title("article three").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addPublishedYear(YEAR_2000).score(20).buildIndex();
IndexQuery article3 = new ArticleEntityBuilder("3").title("article two").subject("computing").addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(30).buildIndex();
IndexQuery article4 = new ArticleEntityBuilder("4").title("article one").subject("accounting").addAuthor(RIZWAN_IDREES).addPublishedYear(YEAR_2002).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000).score(40).buildIndex();
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME);
operations.index(article1, index);
operations.index(article2, index);
operations.index(article3, index);
operations.index(article4, index);
indexOperations.refresh();
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project servicecomb-pack by apache.
the class ElasticsearchTransactionRepository method convert.
private IndexQuery convert(GlobalTransaction transaction) throws JsonProcessingException {
IndexQuery indexQuery = new IndexQuery();
indexQuery.setId(transaction.getGlobalTxId());
indexQuery.setSource(mapper.writeValueAsString(transaction));
return indexQuery;
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class AbstractElasticsearchTemplate method maybeCallbackBeforeConvertWithQuery.
protected void maybeCallbackBeforeConvertWithQuery(Object query, IndexCoordinates index) {
if (query instanceof IndexQuery) {
IndexQuery indexQuery = (IndexQuery) query;
Object queryObject = indexQuery.getObject();
if (queryObject != null) {
queryObject = maybeCallbackBeforeConvert(queryObject, index);
indexQuery.setObject(queryObject);
// the callback might have set som values relevant for the IndexQuery
IndexQuery newQuery = getIndexQuery(queryObject);
if (indexQuery.getRouting() == null && newQuery.getRouting() != null) {
indexQuery.setRouting(newQuery.getRouting());
}
if (indexQuery.getSeqNo() == null && newQuery.getSeqNo() != null) {
indexQuery.setSeqNo(newQuery.getSeqNo());
}
if (indexQuery.getPrimaryTerm() == null && newQuery.getPrimaryTerm() != null) {
indexQuery.setPrimaryTerm(newQuery.getPrimaryTerm());
}
}
}
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class AbstractElasticsearchTemplate method save.
@Override
public <T> T save(T entity, IndexCoordinates index) {
Assert.notNull(entity, "entity must not be null");
Assert.notNull(index, "index must not be null");
T entityAfterBeforeConvert = maybeCallbackBeforeConvert(entity, index);
IndexQuery query = getIndexQuery(entityAfterBeforeConvert);
doIndex(query, index);
// noinspection unchecked
return (T) maybeCallbackAfterSave(Objects.requireNonNull(query.getObject()), index);
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateCallbackTests method indexQueryForEntity.
private IndexQuery indexQueryForEntity(Person entity) {
IndexQuery indexQuery = new IndexQuery();
indexQuery.setObject(entity);
return indexQuery;
}
Aggregations