0

Currently I am creating Elasticsearch Repository with Class ProductSearch, by adding @document annotation with only indexName, the type should be empty as i didn't manage to add any type to the indexname. But when i call productSearchRepository.findByName(query), it searches inside the indexName with type = "productsearch", here is a snippet of the code.

@Document(indexName = "product")
public class ProductSearch extends Product {
}

here is the productSearch repository

@Repository
public interface ProductSearchRepository extends ElasticsearchRepository<ProductSearch, Long> {
    @Query("{\"match\": {\"name.en\" : \"?0\"}}")
    List<ProductSearch> findByName(String name);
}

and here is the logs from elasticsearch which shows that it adds a type = "productsearch"

[2016-10-04 14:03:53,634][WARN ][index.search.slowlog.query] [Apache Kid] [product][1] took[112.3micros], took_millis[0], types[productsearch], stats[], search_type[DFS_QUERY_THEN_FETCH], total_shards[5], source[{"from":0,"size":10,"query_binary":"eyJtYXRjaCI6IHsibmFtZS5lbiIgOiAiYWJjIn19"}], extra_source[], 
[2016-10-04 14:03:53,634][WARN ][index.search.slowlog.query] [Apache Kid] [product][2] took[243.9micros], took_millis[0], types[productsearch], stats[], search_type[DFS_QUERY_THEN_FETCH], total_shards[5], source[{"from":0,"size":10,"query_binary":"eyJtYXRjaCI6IHsibmFtZS5lbiIgOiAiYWJjIn19"}], extra_source[], 
[2016-10-04 14:03:53,634][WARN ][index.search.slowlog.query] [Apache Kid] [product][3] took[154.2micros], took_millis[0], types[productsearch], stats[], search_type[DFS_QUERY_THEN_FETCH], total_shards[5], source[{"from":0,"size":10,"query_binary":"eyJtYXRjaCI6IHsibmFtZS5lbiIgOiAiYWJjIn19"}], extra_source[], 
[2016-10-04 14:03:53,634][WARN ][index.search.slowlog.query] [Apache Kid] [product][4] took[161.5micros], took_millis[0], types[productsearch], stats[], search_type[DFS_QUERY_THEN_FETCH], total_shards[5], source[{"from":0,"size":10,"query_binary":"eyJtYXRjaCI6IHsibmFtZS5lbiIgOiAiYWJjIn19"}], extra_source[], 

What i need is not to create type for my document.

Any help would be appreciated. thanks in advance.

3
  • A (mapping) type is always mandatory, you cannot store a document in an index without specifying a mapping type. Besides, those logs show that the following query is being run {"match": {"name.en" : "abc"}} (decoded from query_binary) and that it is slow (i.e. index.search.slowlog.query). Commented Oct 4, 2016 at 12:23
  • But isn't there any solution to create repository query like this /product/_search not /product/productsearch/_search, please explain further what do you mean by the logs being slow ? Commented Oct 4, 2016 at 12:31
  • Hi! Did you figured that out? It seems that spring-es creates a type, but only by name. But I need to explicetly name some of the fields for the type (because sorting does not work, if the type is not yet known, e.g. if no documents have been storted yet) Commented Dec 1, 2016 at 7:10

1 Answer 1

0

productsearch is simply the name used by Spring Data ES to create the mapping type in your product index.

In your case, searching in /product/_search or /product/productsearch/_search will yield the same results (if you have a single type in the product index, which seems to be the case).

/product/_search is simply a shortcut for searching in all mapping types present in your product index.

You can read here about how to configure slow logs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.