spring-boot-starter-data-elasticsearch 导致未知设置 analyzer/search_analyzer 和 index.settings.analysis.analyzer.autocomplete
spring-boot-starter-data-elasticsearch causing unknown setting analyzer/search_analyzer and index.settings.analysis.analyzer.autocomplete
上下文:我想使用 Spring-Data 连接到 ElasticSearch 并检索数据,在单词的任何位置搜索至少两个字母。
示例:
加载了这两个文档:
[
{
"conta": "1234",
"sobrenome": "Carvalho",
"nome": "Demetrio"
},
{
"conta": "5678",
"sobrenome": "Carv",
"nome": "Deme"
}
]
通过 "de" 或 "me" 搜索 "rio" 将找到所有两个,而搜索 "demet" 只会找到第一个。
我在7.6.2版本中创建这个索引就可以成功了。 (PUT /correntistas)
{
"settings": {
"index.max_ngram_diff": 10,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 2,
"max_gram": 8
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"conta": {
"type": "text"
},
"sobrenome": {
"type": "text"
},
"nome": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
并使用 GET 从 Postman 成功搜索 correntistas/_doc/_search
{
"query" :{
"match" :{
"nome" :"De"
}
}
}
所以,自己的 Elasticsearch 完全没有问题。
但是,问题是从 Spring 数据读取搜索或创建索引。好吧,直接从 Spring 创建索引不是我们将在生产中使用的东西,但它对开发人员来说是值得的。尽管如此,在 ElastiSearch 中搜索 Spring 对我来说是必须的。
完整的日志是
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-11 17:53:35.050 INFO 13020 --- [ main] com.poc.search.SearchApplication : Starting SearchApplication on SPANOT149 with PID 13020 (C:\WSs\elasticsearch\search\target\classes started by Cast in C:\WSs\elasticsearch\search)
2020-05-11 17:53:35.054 INFO 13020 --- [ main] com.poc.search.SearchApplication : No active profile set, falling back to default profiles: default
2020-05-11 17:53:35.624 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2020-05-11 17:53:35.685 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 57ms. Found 1 Elasticsearch repository interfaces.
2020-05-11 17:53:35.844 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
2020-05-11 17:53:35.860 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15ms. Found 0 Reactive Elasticsearch repository interfaces.
2020-05-11 17:53:37.375 INFO 13020 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 17:53:37.386 INFO 13020 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 17:53:37.387 INFO 13020 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-11 17:53:37.531 INFO 13020 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-11 17:53:37.531 INFO 13020 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2379 ms
2020-05-11 17:53:38.646 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : no modules loaded
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2020-05-11 17:53:41.648 INFO 13020 --- [ main] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 192.168.99.100:9300
2020-05-11 17:53:44.203 WARN 13020 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaService': Unsatisfied dependency expressed through field 'correntistaRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'correntistaRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.conta.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
2020-05-11 17:53:45.219 INFO 13020 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-05-11 17:53:45.228 INFO 13020 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-11 17:53:45.239 ERROR 13020 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaService': Unsatisfied dependency expressed through field 'correntistaRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'correntistaRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.conta.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
...
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) ~[netty-transport-4.1.48.Final.jar:4.1.48.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:1050) ~[na:na]
at io.netty.util.internal.ThreadExecutorMap.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
at java.lang.Thread.run(Thread.java:830) ~[na:na]
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.search_analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.sobrenome.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.filter] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.tokenizer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.max_gram] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.min_gram] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.index.max_ngram_diff] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
整个项目可以在搜索文件夹下的 my GitHub repository 中找到。
我相信相关文件是
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.poc</groupId>
<artifactId>search</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>search</name>
<description>Demo project for search-as-user-type cases</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<!-- version>2.2.7.RELEASE</version-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId>
<optional>true</optional> </dependency> -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
型号
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
@Document(indexName = "correntistas")
@Setting(settingPath = "data/es-config/elastic-setting.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 nome;
}
elastic-setting.json(来自 Postman 的索引完全相同)
{
"settings": {
"index.max_ngram_diff": 10,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 2,
"max_gram": 8
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"conta": {
"type": "text"
},
"sobrenome": {
"type": "text"
},
"nome": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
存储库
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import com.poc.search.model.Correntista;
import java.util.List;
@Repository
public interface CorrentistaRepository extends ElasticsearchRepository<Correntista, Long> {
List<Correntista> findAll();
List<Correntista> search(QueryBuilder query);
}
我知道 Elastic 6 和 7 之间存在一些不兼容性,据我所知,Spring-data 仍然没有 7 的依赖性。顺便说一句,我无法将 ElasticSearch 从 7 降级到 6,我确实使用 Spring 编写了一个微服务代码,用于从单词中的任何位置搜索用户类型。我认为主要由 Spring-data-elasticsearch 支持者回答是一个问题或问题,但也许有人可以提出来自 Elasticsearch 用户的另一种选择。拜托,不要建议我既不使用 * 也不使用正则表达式作为替代方案,除非你 100% 它将利用 ElasticSearch 引擎(我很确定在 Elastic 上搜索期间使用 * 是一种糟糕的性能实践)
设置文件存储在哪里?
@Setting(settingPath = "data/es-config/elastic-setting.json")
表示数据目录与实体 class 处于同一级别。
如果你在 src/main/resources/data/es-config 中有它,请更改值:
@Setting(settingPath = "/data/es-config/elastic-setting.json")
编辑:要在 Elasticsearch 7 中使用 Spring Data Elasticsearch,您需要 Spring Data Elasticsearch 4.0,5 月 12 日发布
上下文:我想使用 Spring-Data 连接到 ElasticSearch 并检索数据,在单词的任何位置搜索至少两个字母。
示例:
加载了这两个文档:
[
{
"conta": "1234",
"sobrenome": "Carvalho",
"nome": "Demetrio"
},
{
"conta": "5678",
"sobrenome": "Carv",
"nome": "Deme"
}
]
通过 "de" 或 "me" 搜索 "rio" 将找到所有两个,而搜索 "demet" 只会找到第一个。
我在7.6.2版本中创建这个索引就可以成功了。 (PUT /correntistas)
{
"settings": {
"index.max_ngram_diff": 10,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 2,
"max_gram": 8
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"conta": {
"type": "text"
},
"sobrenome": {
"type": "text"
},
"nome": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
并使用 GET 从 Postman 成功搜索 correntistas/_doc/_search
{
"query" :{
"match" :{
"nome" :"De"
}
}
}
所以,自己的 Elasticsearch 完全没有问题。
但是,问题是从 Spring 数据读取搜索或创建索引。好吧,直接从 Spring 创建索引不是我们将在生产中使用的东西,但它对开发人员来说是值得的。尽管如此,在 ElastiSearch 中搜索 Spring 对我来说是必须的。
完整的日志是
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-11 17:53:35.050 INFO 13020 --- [ main] com.poc.search.SearchApplication : Starting SearchApplication on SPANOT149 with PID 13020 (C:\WSs\elasticsearch\search\target\classes started by Cast in C:\WSs\elasticsearch\search)
2020-05-11 17:53:35.054 INFO 13020 --- [ main] com.poc.search.SearchApplication : No active profile set, falling back to default profiles: default
2020-05-11 17:53:35.624 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2020-05-11 17:53:35.685 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 57ms. Found 1 Elasticsearch repository interfaces.
2020-05-11 17:53:35.844 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
2020-05-11 17:53:35.860 INFO 13020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15ms. Found 0 Reactive Elasticsearch repository interfaces.
2020-05-11 17:53:37.375 INFO 13020 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 17:53:37.386 INFO 13020 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 17:53:37.387 INFO 13020 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-11 17:53:37.531 INFO 13020 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-11 17:53:37.531 INFO 13020 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2379 ms
2020-05-11 17:53:38.646 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : no modules loaded
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2020-05-11 17:53:38.647 INFO 13020 --- [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2020-05-11 17:53:41.648 INFO 13020 --- [ main] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 192.168.99.100:9300
2020-05-11 17:53:44.203 WARN 13020 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaService': Unsatisfied dependency expressed through field 'correntistaRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'correntistaRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.conta.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
2020-05-11 17:53:45.219 INFO 13020 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-05-11 17:53:45.228 INFO 13020 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-11 17:53:45.239 ERROR 13020 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'correntistaService': Unsatisfied dependency expressed through field 'correntistaRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'correntistaRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.conta.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
...
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) ~[netty-transport-4.1.48.Final.jar:4.1.48.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:1050) ~[na:na]
at io.netty.util.internal.ThreadExecutorMap.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
at java.lang.Thread.run(Thread.java:830) ~[na:na]
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.search_analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.nome.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.mappings.properties.sobrenome.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.filter] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.tokenizer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.analyzer.autocomplete.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.max_gram] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.min_gram] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.analysis.filter.autocomplete_filter.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
Suppressed: java.lang.IllegalArgumentException: unknown setting [index.settings.index.max_ngram_diff] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
... 59 common frames omitted
整个项目可以在搜索文件夹下的 my GitHub repository 中找到。
我相信相关文件是
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.poc</groupId>
<artifactId>search</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>search</name>
<description>Demo project for search-as-user-type cases</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<!-- version>2.2.7.RELEASE</version-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId>
<optional>true</optional> </dependency> -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
型号
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
@Document(indexName = "correntistas")
@Setting(settingPath = "data/es-config/elastic-setting.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 nome;
}
elastic-setting.json(来自 Postman 的索引完全相同)
{
"settings": {
"index.max_ngram_diff": 10,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 2,
"max_gram": 8
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"conta": {
"type": "text"
},
"sobrenome": {
"type": "text"
},
"nome": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
存储库
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import com.poc.search.model.Correntista;
import java.util.List;
@Repository
public interface CorrentistaRepository extends ElasticsearchRepository<Correntista, Long> {
List<Correntista> findAll();
List<Correntista> search(QueryBuilder query);
}
我知道 Elastic 6 和 7 之间存在一些不兼容性,据我所知,Spring-data 仍然没有 7 的依赖性。顺便说一句,我无法将 ElasticSearch 从 7 降级到 6,我确实使用 Spring 编写了一个微服务代码,用于从单词中的任何位置搜索用户类型。我认为主要由 Spring-data-elasticsearch 支持者回答是一个问题或问题,但也许有人可以提出来自 Elasticsearch 用户的另一种选择。拜托,不要建议我既不使用 * 也不使用正则表达式作为替代方案,除非你 100% 它将利用 ElasticSearch 引擎(我很确定在 Elastic 上搜索期间使用 * 是一种糟糕的性能实践)
设置文件存储在哪里?
@Setting(settingPath = "data/es-config/elastic-setting.json")
表示数据目录与实体 class 处于同一级别。 如果你在 src/main/resources/data/es-config 中有它,请更改值:
@Setting(settingPath = "/data/es-config/elastic-setting.json")
编辑:要在 Elasticsearch 7 中使用 Spring Data Elasticsearch,您需要 Spring Data Elasticsearch 4.0,5 月 12 日发布