Java Code Examples for org.springframework.data.elasticsearch.core.query.IndexQuery#setId()

The following examples show how to use org.springframework.data.elasticsearch.core.query.IndexQuery#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchTransactionRepository.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
private IndexQuery convert(GlobalTransaction transaction) throws JsonProcessingException {
  IndexQuery indexQuery = new IndexQuery();
  indexQuery.setId(transaction.getGlobalTxId());
  indexQuery.setSource(mapper.writeValueAsString(transaction));
  indexQuery.setIndexName(INDEX_NAME);
  indexQuery.setType(INDEX_TYPE);
  return indexQuery;
}
 
Example 2
Source File: ArticleBuilder.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
public IndexQuery buildIndex() {
    IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(result.getId());
    indexQuery.setObject(result);
    return indexQuery;
}
 
Example 3
Source File: NestedObjectTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@Test
public void shouldIndexInitialLevelNestedObject() {

    List<Car> cars = new ArrayList<Car>();

    Car saturn = new Car();
    saturn.setName("Saturn");
    saturn.setModel("SL");

    Car subaru = new Car();
    subaru.setName("Subaru");
    subaru.setModel("Imprezza");

    Car ford = new Car();
    ford.setName("Ford");
    ford.setModel("Focus");

    cars.add(saturn);
    cars.add(subaru);
    cars.add(ford);

    Person foo = new Person();
    foo.setName("Foo");
    foo.setId("1");
    foo.setCar(cars);

    Car car = new Car();
    car.setName("Saturn");
    car.setModel("Imprezza");

    Person bar = new Person();
    bar.setId("2");
    bar.setName("Bar");
    bar.setCar(Arrays.asList(car));

    List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
    IndexQuery indexQuery1 = new IndexQuery();
    indexQuery1.setId(foo.getId());
    indexQuery1.setObject(foo);

    IndexQuery indexQuery2 = new IndexQuery();
    indexQuery2.setId(bar.getId());
    indexQuery2.setObject(bar);

    indexQueries.add(indexQuery1);
    indexQueries.add(indexQuery2);

    elasticsearchTemplate.putMapping(Person.class);
    elasticsearchTemplate.bulkIndex(indexQueries);
    elasticsearchTemplate.refresh(Person.class);

    QueryBuilder builder = nestedQuery("car",
        boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")),
        ScoreMode.Total);

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
    List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);

    assertThat(persons.size(), is(1));
}
 
Example 4
Source File: NestedObjectTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
private List<IndexQuery> createPerson() {

        PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();

        person1.setId("1");
        person1.setName("name");

        Car saturn = new Car();
        saturn.setName("Saturn");
        saturn.setModel("SL");

        Car subaru = new Car();
        subaru.setName("Subaru");
        subaru.setModel("Imprezza");

        Car car = new Car();
        car.setName("Saturn");
        car.setModel("Imprezza");

        Car ford = new Car();
        ford.setName("Ford");
        ford.setModel("Focus");

        GirlFriend permanent = new GirlFriend();
        permanent.setName("permanent");
        permanent.setType("permanent");
        permanent.setCars(Arrays.asList(saturn, subaru));

        GirlFriend temp = new GirlFriend();
        temp.setName("temp");
        temp.setType("temp");
        temp.setCars(Arrays.asList(car, ford));

        person1.setGirlFriends(Arrays.asList(permanent, temp));

        IndexQuery indexQuery1 = new IndexQuery();
        indexQuery1.setId(person1.getId());
        indexQuery1.setObject(person1);

        PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();

        person2.setId("2");
        person2.setName("name");

        person2.setGirlFriends(Arrays.asList(permanent));

        IndexQuery indexQuery2 = new IndexQuery();
        indexQuery2.setId(person2.getId());
        indexQuery2.setObject(person2);

        List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
        indexQueries.add(indexQuery1);
        indexQueries.add(indexQuery2);

        return indexQueries;
    }
 
Example 5
Source File: ArticleBuilder.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
public IndexQuery buildIndex() {
    IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(result.getId());
    indexQuery.setObject(result);
    return indexQuery;
}
 
Example 6
Source File: NestedObjectTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@Test
public void shouldIndexInitialLevelNestedObject() {

    List<Car> cars = new ArrayList<Car>();

    Car saturn = new Car();
    saturn.setName("Saturn");
    saturn.setModel("SL");

    Car subaru = new Car();
    subaru.setName("Subaru");
    subaru.setModel("Imprezza");

    Car ford = new Car();
    ford.setName("Ford");
    ford.setModel("Focus");

    cars.add(saturn);
    cars.add(subaru);
    cars.add(ford);

    Person foo = new Person();
    foo.setName("Foo");
    foo.setId("1");
    foo.setCar(cars);

    Car car = new Car();
    car.setName("Saturn");
    car.setModel("Imprezza");

    Person bar = new Person();
    bar.setId("2");
    bar.setName("Bar");
    bar.setCar(Arrays.asList(car));

    List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
    IndexQuery indexQuery1 = new IndexQuery();
    indexQuery1.setId(foo.getId());
    indexQuery1.setObject(foo);

    IndexQuery indexQuery2 = new IndexQuery();
    indexQuery2.setId(bar.getId());
    indexQuery2.setObject(bar);

    indexQueries.add(indexQuery1);
    indexQueries.add(indexQuery2);

    elasticsearchTemplate.putMapping(Person.class);
    elasticsearchTemplate.bulkIndex(indexQueries);
    elasticsearchTemplate.refresh(Person.class);

    QueryBuilder builder = nestedQuery("car",
        boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")),
        ScoreMode.Total);

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
    List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);

    assertThat(persons.size(), is(1));
}
 
Example 7
Source File: NestedObjectTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
private List<IndexQuery> createPerson() {

        PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();

        person1.setId("1");
        person1.setName("name");

        Car saturn = new Car();
        saturn.setName("Saturn");
        saturn.setModel("SL");

        Car subaru = new Car();
        subaru.setName("Subaru");
        subaru.setModel("Imprezza");

        Car car = new Car();
        car.setName("Saturn");
        car.setModel("Imprezza");

        Car ford = new Car();
        ford.setName("Ford");
        ford.setModel("Focus");

        GirlFriend permanent = new GirlFriend();
        permanent.setName("permanent");
        permanent.setType("permanent");
        permanent.setCars(Arrays.asList(saturn, subaru));

        GirlFriend temp = new GirlFriend();
        temp.setName("temp");
        temp.setType("temp");
        temp.setCars(Arrays.asList(car, ford));

        person1.setGirlFriends(Arrays.asList(permanent, temp));

        IndexQuery indexQuery1 = new IndexQuery();
        indexQuery1.setId(person1.getId());
        indexQuery1.setObject(person1);

        PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();

        person2.setId("2");
        person2.setName("name");

        person2.setGirlFriends(Arrays.asList(permanent));

        IndexQuery indexQuery2 = new IndexQuery();
        indexQuery2.setId(person2.getId());
        indexQuery2.setObject(person2);

        List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
        indexQueries.add(indexQuery1);
        indexQueries.add(indexQuery2);

        return indexQueries;
    }