检索组件elasticsearch
Elasticsearch是一个分布式搜索服务,提供restful API 底层基于Lucene,采用多shard(分片)的方式保证数据安全,并且提供自动resharding的功能,github等大型站点也是采用了Elasticsearch作为其搜索服务;
docker search elasticsearch
docker pull elasticsearch:7.17.1
docker images
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -e "discovery.type=single-node" -d -p 9200:9200 -p 9300:9300 --name ES01 515ab4fba870
{
"name" : "5ab04951e8e0",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "v_6fQnhsQ8i1S0faXaTo2A",
"version" : {
"number" : "7.17.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a",
"build_date" : "2022-02-23T22:20:54.153567231Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
具体操作参考:
elasticsearch官方文档【中文】
或者关注后续的elasticsearch学习文档
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
org.springframework.boot.autoconfigure在自动配置包下的data.elasticsearch和elasticsearch下分别对应两种ES加护技术;org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration中引入了ElasticsearchRestTemplate和ElasticsearchRepositoryorg.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration引入RestHighLevelClientspring:
elasticsearch:
uris: http://192.168.1.132:9200
@Autowired
RestHighLevelClient restHighLevelClient;
@Test
void contextLoads() throws IOException {
final GetRequest getRequest = new GetRequest();
getRequest.id("1");
getRequest.index("book");
final GetResponse documentFields = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
final String sourceAsString = documentFields.getSourceAsString();
System.out.println("sourceAsString = " + sourceAsString);
}
@Autowired
ElasticsearchRestTemplate template;
@Test
void contextLoads3() throws IOException {
final Book book = template.get("1", Book.class);
System.out.println("book = " + book);
}
public interface BookRepository extends ElasticsearchRepository<Book,Long> {
List<Book> findByAuthorLike(String author);
}
@Autowired
BookRepository repository;
@Test
void contextLoads() {
/*Book book = new Book(1L,"红楼梦","曹雪芹");
repository.save(book);*/
for (Book book1 : repository.findAll()) {
System.out.println("book1 = " + book1);
}
}
我试图在我的网站上实现使用Facebook登录功能,但在尝试从Facebook取回访问token时遇到障碍。这是我的代码:ifparams[:error_reason]=="user_denied"thenflash[:error]="TologinwithFacebook,youmustclick'Allow'toletthesiteaccessyourinformation"redirect_to:loginelsifparams[:code]thentoken_uri=URI.parse("https://graph.facebook.com/oauth/access_token
不知何故,我似乎无法获得包含我的聚合的响应...使用curl它按预期工作:HBZUMB01$curl-XPOST"http://localhost:9200/contents/_search"-d'{"size":0,"aggs":{"sport_count":{"value_count":{"field":"dwid"}}}}'我收到回复:{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":90,"max_score":0.0,"hits":[]},"a
1.回顾.TransportServicepublicclassTransportServiceextendsAbstractLifecycleComponentTransportService:方法:1publicfinalTextendsTransportResponse>voidsendRequest(finalTransport.Connectionconnection,finalStringaction,finalTransportRequestrequest,finalTransportRequestOptionsoptions,TransportResponseHandlerT>
我有一个Rails应用程序,现在设置了ElasticSearch和Tiregem以在模型上进行搜索,我想知道我应该如何设置我的应用程序以对模型中的某些索引进行模糊字符串匹配。我将我的模型设置为索引标题、描述等内容,但我想对其中一些进行模糊字符串匹配,但我不确定在何处进行此操作。如果您想发表评论,我将在下面包含我的代码!谢谢!在Controller中:defsearch@resource=Resource.search(params[:q],:page=>(params[:page]||1),:per_page=>15,load:true)end在模型中:classResource'Us
我正在使用RubyonRailsv3.0.9,我想检索我设置了链接的每个网站的favicon.ico图像。也就是说,如果在我的应用程序中我设置了http://www.facebook.com/URL,我想检索Facebook的图标并在我的网页中使用\插入它。当然,我也想为所有其他网站这样做。如何以“自动”方式从网站检索favicon.ico图标(“自动”是指在网站中搜索图标并获取它的链接-我认为不是,因为并非所有网站都有一个名为“favicon.ico”的图标。我想以“自动”方式识别它)?P.S.:我想做的是像Facebook在您的Facebook页面中添加链接\URL时所做的那样:它
我想从C函数返回多个值,恕我直言,散列是一个不错的选择。我首先使用rb_intern('A_KEY')创建key,但扩展崩溃了。现在,我正在使用rb_str_new2,但我更喜欢符号。如何创建一个新符号,并在不引用类或方法的情况下使用它? 最佳答案 您需要使用ID2SYM宏将从rb_intern获得的标识符转换为ruby符号。尝试改变rb_intern('A_KEY')到ID2SYM(rb_intern('A_KEY')) 关于c-我如何在Ruby的C扩展API上检索'standal
美团外卖搜索工程团队在Elasticsearch的优化实践中,基于Location-BasedService(LBS)业务场景对Elasticsearch的查询性能进行优化。该优化基于Run-LengthEncoding(RLE)设计了一款高效的倒排索引结构,使检索耗时(TP99)降低了84%。本文从问题分析、技术选型、优化方案等方面进行阐述,并给出最终灰度验证的结论。1.前言最近十年,Elasticsearch已经成为了最受欢迎的开源检索引擎,其作为离线数仓、近线检索、B端检索的经典基建,已沉淀了大量的实践案例及优化总结。然而在高并发、高可用、大数据量的C端场景,目前可参考的资料并不多。因此
开门见山|拉取镜像dockerpullelasticsearch:7.16.1|配置存放的目录#存放配置文件的文件夹mkdir-p/opt/docker/elasticsearch/node-1/config#存放数据的文件夹mkdir-p/opt/docker/elasticsearch/node-1/data#存放运行日志的文件夹mkdir-p/opt/docker/elasticsearch/node-1/log#存放IK分词插件的文件夹mkdir-p/opt/docker/elasticsearch/node-1/plugins若你使用了moba,直接右键新建即可如上图所示依次类推创建
文章目录概念索引相关操作创建索引更新副本查看索引删除索引索引的打开与关闭收缩索引索引别名查询索引别名文档相关操作新建文档查询文档更新文档删除文档映射相关操作查询文档映射创建静态映射创建索引并添加映射概念es中有三个概念要清楚,分别为索引、映射和文档(不用死记硬背,大概有个印象就可以)索引可理解为MySQL数据库;映射可理解为MySQL的表结构;文档可理解为MySQL表中的每行数据静态映射和动态映射上面已经介绍了,映射可理解为MySQL的表结构,在MySQL中,向表中插入数据是需要先创建表结构的;但在es中不必这样,可以直接插入文档,es可以根据插入的文档(数据),动态的创建映射(表结构),这就
如果您希望在Spring中启用定时任务功能,则需要在主类上添加 @EnableScheduling 注解。这样Spring才会扫描 @Scheduled 注解并执行定时任务。在大多数情况下,只需要在主类上添加 @EnableScheduling 注解即可,不需要在Service层或其他类中再次添加。以下是一个示例,演示如何在SpringBoot中启用定时任务功能:@SpringBootApplication@EnableSchedulingpublicclassApplication{publicstaticvoidmain(String[]args){SpringApplication.ru