目前我正在使用类ProductSearch创建Elasticsearch存储库,通过仅添加带有indexName的@document注释,该类型应为空,因为我没有设法将任何类型添加到indexname。但是当我调用productSearchRepository.findByName(query)时,它会在indexName中使用type =“productsearch”进行搜索,这里是代码片段。
@Document(indexName = "product")
public class ProductSearch extends Product {
}
这是productSearch存储库
@Repository
public interface ProductSearchRepository extends ElasticsearchRepository<ProductSearch, Long> {
@Query("{\"match\": {\"name.en\" : \"?0\"}}")
List<ProductSearch> findByName(String name);
}
这是来自elasticsearch的日志,它显示它添加了一个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[],
我需要的不是为我的文档创建类型。
任何帮助将不胜感激。 提前谢谢。
答案 0 :(得分:0)
productsearch
只是Spring Data ES用于在product
索引中创建映射类型的名称。
在您的情况下,在/product/_search
或/product/productsearch/_search
中搜索会产生相同的结果(如果您在product
索引中只有一种类型,则情况似乎如此)。
/product/_search
只是用于搜索product
索引中存在的所有地图类型的快捷方式。
您可以阅读有关如何配置慢速日志的here。