1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| @SpringBootTest public class EsDemoApplicationTests { @Autowired private CountrySearchRepository countrySearchRepository;
@Test public void testSaveCountryIndex() { Country country = new Country(); country.setId(1); country.setName("China"); Country country2 = new Country(); country2.setId(2); country2.setName("America"); List<Country> countryList = new ArrayList<>(2); countryList.add(country); countryList.add(country2); countrySearchRepository.saveAll(countryList); }
@Test public void testSearch() { String queryString = "china"; QueryStringQueryBuilder builder=new QueryStringQueryBuilder(queryString); Iterable<Country> searchResult = countrySearchRepository.search(builder); Iterator<Country> iterator = searchResult.iterator(); while(iterator.hasNext()){ System.out.println(iterator.next()); } }
}
|