Search in sources :

Example 11 with IndexQuery

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();
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with IndexQuery

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;
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery)

Example 13 with 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());
            }
        }
    }
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery)

Example 14 with IndexQuery

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);
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery)

Example 15 with IndexQuery

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;
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery)

Aggregations

IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)31 Test (org.junit.jupiter.api.Test)12 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)9 ArrayList (java.util.ArrayList)8 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)8 DisplayName (org.junit.jupiter.api.DisplayName)4 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)4 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)4 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 HashMap (java.util.HashMap)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SeqNoPrimaryTerm (org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm)2 Commodity (com.example.esdemo.dto.Commodity)1 CommonException (com.huaxing.springboot_elasticsearch.common.utils.CommonException)1 UserEntity (com.javayh.elaticsearh.docment.UserEntity)1 Field (java.lang.reflect.Field)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1