- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
用户案例:我想按照用户类型搜索模式使用SpringBoot和ElasticSearch开发微服务。换句话说,如果我输入“d”,我想回信Demetrio,Denis和Daniel。输入第二个字母“e”会带来Demetrio和Denis,最后输入第三个字母将检索确切的名称。即使输入中间字母也应该带来。 “en”应该带丹尼斯和丹尼尔。搜索作为用户类型的常见情况。
我正在研究以下方面的建议:
edgengram
search-as-you-type field type
search-analyzer
当前问题:当我启动旨在创建和设置ElasticSearch的应用程序时,我从这个问题主题中得到了异常(exception)。索引创建成功,我的初始数据已加载,但似乎分析仪被完全忽略了。
引导SpringBoot时的完整日志:
2020-04-10 14:27:40.281 INFO 16556 --- [ main] com.poc.search.SearchApplication : Starting SearchApplication on SPANOT164 with PID 16556 (C:\WSs\elasticsearch\search\target\classes started by Cast in C:\WSs\elasticsearch\search)
2020-04-10 14:27:40.286 INFO 16556 --- [ main] com.poc.search.SearchApplication : No active profile set, falling back to default profiles: default
2020-04-10 14:27:40.863 INFO 16556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2020-04-10 14:27:40.931 INFO 16556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 62ms. Found 1 Elasticsearch repository interfaces.
2020-04-10 14:27:41.101 INFO 16556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
2020-04-10 14:27:41.120 INFO 16556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 13ms. Found 0 Reactive Elasticsearch repository interfaces.
2020-04-10 14:27:42.343 INFO 16556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-04-10 14:27:42.360 INFO 16556 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-10 14:27:42.360 INFO 16556 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-10 14:27:42.496 INFO 16556 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-10 14:27:42.496 INFO 16556 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2122 ms
2020-04-10 14:27:43.221 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : no modules loaded
2020-04-10 14:27:43.222 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2020-04-10 14:27:43.222 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2020-04-10 14:27:43.222 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2020-04-10 14:27:43.222 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2020-04-10 14:27:43.222 INFO 16556 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2020-04-10 14:27:45.480 INFO 16556 --- [ main] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 127.0.0.1:9300
2020-04-10 14:27:47.539 ERROR 16556 --- [ main] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.index.mapper.MapperParsingException: analyzer [autocomplete_index] not found for field [palavra]
2020-04-10 14:27:47.775 INFO 16556 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-10 14:27:48.333 INFO 16556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-10 14:27:48.334 INFO 16556 --- [ main] com.poc.search.SearchApplication : Started SearchApplication in 8.714 seconds (JVM running for 9.159)
{
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete_search": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
},
"autocomplete_index": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.poc.search.model.Correntista;
import com.poc.search.service.CorrentistaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Component
public class ElasticSearchDataLoader implements CommandLineRunner {
@Value("classpath:data/correntistas.json")
private Resource usersJsonFile;
@Autowired
private CorrentistaService correntistaService;
@Override
public void run(String... args) throws Exception {
if (this.isInitialized()) {
return;
}
List<Correntista> users = this.loadUsersFromFile();
users.forEach(correntistaService::save);
}
private List<Correntista> loadUsersFromFile() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(List.class, CorrentistaInitData.class);
List<CorrentistaInitData> allFakeUsers = objectMapper.readValue(this.usersJsonFile.getFile(), collectionType);
return allFakeUsers.stream().map(this::from).map(this::generateId).collect(Collectors.toList());
}
private Correntista generateId(Correntista correntista) {
correntista.setId(UUID.randomUUID().toString());
return correntista;
}
private Correntista from(CorrentistaInitData correntistaJson) {
Correntista correntista = new Correntista();
correntista.setConta(correntistaJson.getConta());
correntista.setSobrenome(correntistaJson.getSobrenome());
correntista.setPalavra(correntistaJson.getNome());
return correntista;
}
private boolean isInitialized() {
return this.correntistaService.count() > 0;
}
}
@Document(indexName = "correntistas")
@Setting(settingPath = "es-config/elastic-analyzer.json")
@Getter
@Setter
public class Correntista {
@Id
private String id;
private String conta;
private String sobrenome;
@Field(type = FieldType.Text, analyzer = "autocomplete_index", searchAnalyzer = "autocomplete_search")
private String palavra;
}
spring:
data:
elasticsearch:
cluster-name: docker-cluster
cluster-nodes: localhost:9300
@EnableElasticsearchRepositories
@SpringBootApplication
public class SearchApplication {
public static void main(String[] args) {
SpringApplication.run(SearchApplication.class, args);
}
}
{
"correntistas": {
"settings": {
"index": {
"refresh_interval": "1s",
"number_of_shards": "5",
"provided_name": "correntistas",
"creation_date": "1586539666845",
"store": {
"type": "fs"
},
"number_of_replicas": "1",
"uuid": "2eEha4aMQm2bdut4pd0aAg",
"version": {
"created": "6080499"
}
}
}
}
}
{
"took": 66,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.0,
"hits": [
{
"_index": "correntistas",
"_type": "correntista",
"_id": "7353cd8c-791d-47f5-90b6-a1b5bcf83853",
"_score": 1.0,
"_source": {
"id": "7353cd8c-791d-47f5-90b6-a1b5bcf83853",
"conta": "1234",
"sobrenome": "Carvalho",
"palavra": "Demetrio"
}
},
{
"_index": "correntistas",
"_type": "correntista",
"_id": "122db1bc-584d-4bef-b5ea-3d9e0d42448e",
"_score": 1.0,
"_source": {
"id": "122db1bc-584d-4bef-b5ea-3d9e0d42448e",
"conta": "5678",
"sobrenome": "Carv",
"palavra": "Deme"
}
}
]
}
}
最佳答案
在对所写文件的描述中:
elastic-analyzer.json from resources/data/es-config
@Setting
批注中,缺少该路径中的数据部分。您应该将其更改为:
@Setting(settingPath = "data/es-config/elastic-analyzer.json")
save
,而应将它们收集在一个列表中,并使用
saveAll
进行批处理插入,这会提高性能。
关于spring-boot - AbstractElasticsearchRepository:无法加载elasticsearch节点:MapperParsingException:找不到字段的分析器[autocomplete_index],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61145858/
尝试上传大型json文件时,我收到了MapperParsingException。这是我从elasticsearch得到的完整错误: on [[sample][4]] MapperParsingExc
我正在尝试将以下数据索引到elasticsearch中, { "_id": "5619578c1983757a72efef15", "aseg": {}, "cs": { "source":
我关注了一篇关于 ElasticSearch 的文章,并尝试将这个示例放在我的引擎上。 例子: curl -XPUT 'elasticsearch:9200/twitter/tweet/1' -d '
我正在尝试使用C#中的BulkDescriptor将文档批量索引到ES中。我正在使用V1.7 ES。以下是我的代码, public IBulkResponse IndexBulk(string in
我正在将Elasticsearch 1.2.2与PHP包装器Elastica一起使用 在索引某些文档时,我遇到以下异常 PHP Fatal error: Uncaught exception 'El
我正在开发一个ES插件,其中包含一个新的分析器和一个新的过滤器。 我的elasticsearch.yml文件如下: index: analysis: analyzer:
我想使用 Java 中的 Apache HttpClient 添加一个条目到 Elasticsearch。 HttpClient httpclient = HttpClients.createDefa
我正在尝试将 MYSQL 集成到 Windows 7 上的 ElasticSearch 中 link 我已经完成了以下步骤: 1: Download & Unzip in C Directory ht
我在Elasticsearch群集上有一个索引,并且我想支持语音匹配。 这是我的要求: curl -XPUT "http://localhost:9200/propertywebsites/_mapp
我使用的是 Elasticsearch 版本 1.2.0,Jdbc river 版本 1.2.0.1。 以下是我的Jdbc river命令。 curl -XPUT 'localhost:9200/_r
我使用了 elasticsearch 教程中的命令, curl -XPUT "http://localhost:9200/movies/movie/1" -d" { "title": "The God
如何将 Django 模型的 Postgres JsonField 映射到 ElasticSearch 索引?是否有任何解决方法可以使其正常工作? 引用:https://github.com/sabr
用户案例:我想按照用户类型搜索模式使用SpringBoot和ElasticSearch开发微服务。换句话说,如果我输入“d”,我想回信Demetrio,Denis和Daniel。输入第二个字母“e”会
我已经建立了一个基本的ELK堆栈,用于处理和显示apache日志。它在过去1个月内一直在工作,但是从最近两天开始突然出现, flex 搜索引发了以下错误。 MapperParsingException
我使用以下设置在 Elasticsearch 中创建了一个索引: { "my_index" : { "aliases" : { }, "mappings" : { }, "
我正在使用 java 1.7.0_95、Django 1.8.4、Python 3.4.0、Django Rest Framework 3.1 .3、ElasticSearch 2.3.1、pyela
我尝试使用命令插入我的 JSON 文件 curl -XPOST ' http://localhost:9200/test/sec5/1 ' -d @quality.json [ { "Pr
尝试使用 node.js 的 http 模块将记录插入 ElasticSearch(不使用第 3 方模块) 设置:在端口9200(默认)上本地运行 ElasticSearch 实例(默认) Node.
我的本地 ES 1.3.4 实例和 JDBC For MySql 1.3.4.4 上有一条 River 这条河流运行良好,正在 ES 中导入数据。我面临的问题是我的字段之一是文本字段并且其中有空格
在 ElasicSearch 中,我创建了一个索引“测试”和如下所示的映射 { "index": { "_index": "test", "_type": "test" },
我是一名优秀的程序员,十分优秀!