deanonimus/README.md
Anatolii Karlov 4fdca4bf68
OPS-407: refactor search query, use keywords (#49)
* OPS-407: refactor search query, use keywords

* OPS-407: refactor search query, use keywords

* OPS-407: refactor search query, use keywords
2024-02-12 12:41:33 +02:00

1.4 KiB
Raw Permalink Blame History

deanonimus

Сервис для полнотекстового поиска party

актуальные примеры с spring data elastic + opensearch

https://github.com/opensearch-project/spring-data-opensearch/blob/main/spring-data-opensearch-examples/spring-boot-gradle/src/main/java/org/opensearch/data/example/service/MarketplaceInitializer.java
https://github.com/M-Razavi/Spring-Data-OpenSearch-Example

полезные ссылки
https://opensearch.org/docs/latest/query-dsl/full-text/index/
https://opensearch.org/docs/latest/query-dsl/full-text/multi-match/

сниппеты

getMappingResponse.get("party").mappings().properties().get("id").text().fields().get("keyword").keyword()

search.hits().hits().get(0).source()

var criteria = QueryBuilders.boolQuery()
        .must(QueryBuilders.matchQuery("authorName", author))
        .must(QueryBuilders.matchQuery("title", title));

SearchRequest searchRequest = new SearchRequest("books");
        searchRequest.source().query(criteria);

        try {
SearchResponse response = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
            return Arrays.stream(response.getHits().getHits())
        .map(hit -> new ObjectMapper().convertValue(hit.getSourceAsMap(), Book.class))
        .collect(Collectors.toList());
        } catch (IOException e) {
        throw new RuntimeException("Error executing search", e);
        }