Spring-Data-Elasticsearch设置:Spring找不到配置文件? [英] Spring-Data-Elasticsearch settings: Spring can't find config file?
问题描述
使用Spring-Data-Elasticsearch,我试图使用在< em> elasticsearch_config.json 中定义的分析器和映射。
此JSON文件位于 / src / main /资源文件夹。
我的JAVA模型看起来像:
@Setting(settingPath =/elasticsearch_config.json)public class Tweet $ {code} @Document(indexName =test,type =Tweet b
$ b @Id
private String idStr;
/ **其他字段,getter和setter被省略** /
}
elasticsearch_config.json 包含设置和映射:
{
settings:{/ * some filters * /},
mappings:{/ * some types'mappings * /}
}
我尝试了卷曲,索引/搜索没有问题。
我的问题:
我想使用 @Setting 来配置我的映射(不是卷曲),但是设置注释似乎不起作用。
使用 @Setting ,当我使用curl检查我的映射时,我没有得到我在elasticsearch_config.json中定义的所有映射:
curl -X GETlocalhost:9200 / test / _mapping?pretty = true
pre>
我的猜测是Spring无法正确找到 elasticsearch_config.json 。
但是我已经检查了我的项目的构建路径中的 myproject / src / main / resources ...
任何帮助,谢谢!
备注:
我发现这个可能有效的解决方案,但是:
1.我不明白nodeBuilder来自哪里br>
2.我可能错了,但是是否只有使用 @Setting 的解决方案?
更新:我的映射
我从分析器中分离出映射。{
mappings:{
Tweet:{
_id:{
path:idStr,
properties:{
idStr:{
type:string,
index:not_analyzed,
store:true
}
}
},
numeric_detection:true,
dynamic_templates:[
{
id_fields:{
match:userId *,
match_mapping_type字符串,
映射:{
type:string,
index:no,
store:true
}
}
{
name_fields:{
match:* Name,
match_mapping_type:string
映射:{
type:string,
index:no,
sto re:true
}
}
}
],
properties:{
text:{
type :string,
index:analyze,
analyzer:custom_analyzer,
store:true
},
createdAt :{
type:date,
format:yyyy-MM-dd,
index:analyze,
store :
},
testVersion:{
type:integer,
index:not_analyzed,
store:false
}
}
}
}
}
解决方案最后找出为什么它不工作!!
像Val说,我将我的 elasticsearch_config.json 文件分解为 settings.json 和 mappings.json 。
我的项目/ src / main / ressources架构:
- mappings
+ mappings.json
- 设置
+ settings.json
和
@Document(indexName =test ,type =SentimentTweet)
@Setting(settingPath =/settings/settings.json)
@Mapping(mappingPath =/mappings/mappings.json)
然而,在
mappings.json 中,我应该省略字段映射直接提交映射的内容。
INSTEAD OF:
{
mappings:{
Tweet:{
/ *映射配置为* /
}
}
}
只能在mappings.json中写入:
{
/ pre>
Tweet:{
/ *映射配置被忽略* /
}
}
同样应该为settings.json
With Spring-Data-Elasticsearch, I am trying to use analyzers and mappings defined in elasticsearch_config.json.
This JSON file is in /src/main/resources folder.My JAVA model looks like:
@Document(indexName = "test", type="Tweet") @Setting(settingPath = "/elasticsearch_config.json") public class Tweet { @Id private String idStr; /** other fields, getters and setters are omitted **/ }
elasticsearch_config.json contains both settings and mappings:
{ "settings": { /* some filters */}, "mappings": { /* some types' mappings*/ } }
I tried with curl, I get no problem indexing/searching.
My problem:
I want to use @Setting to configure my mappings (not curl), but @Setting annotation doesn't seem to work. With @Setting, when I use curl to check my mapping, I don't get all the mappings I defined in elasticsearch_config.json :
curl -X GET "localhost:9200/test/_mapping?pretty=true"
My guess is that Spring can't find the elasticsearch_config.json properly. However I have already checked that myproject/src/main/resources is in my project's build path...
I appreciate any help, thank you!
Notes: I have found this solution that may work, but:
1. I don't understand where nodeBuilder comes from
2. I may be wrong but, isn't there a solution only using @Setting?UPDATES: My mappings I separeted analyzers from mappings. mappings.json looks like this:
{ "mappings": { "Tweet": { "_id": { "path":"idStr", "properties": { "idStr": { "type":"string", "index":"not_analyzed", "store":true } } }, "numeric_detection" : true, "dynamic_templates": [ { "id_fields": { "match":"userId*", "match_mapping_type": "string", "mapping": { "type":"string", "index":"no", "store":true } } }, { "name_fields": { "match":"*Name", "match_mapping_type": "string", "mapping": { "type":"string", "index":"no", "store":true } } } ], "properties": { "text": { "type": "string", "index":"analyzed", "analyzer":"custom_analyzer", "store": true }, "createdAt": { "type": "date", "format": "yyyy-MM-dd", "index":"analyzed", "store": true }, "testVersion": { "type": "integer", "index":"not_analyzed", "store":false } } } } }
解决方案Finally found out why it was not working!!
Like Val said, I decomposed my elasticsearch_config.json file into settings.json and mappings.json.
My project/src/main/ressources architecture:
- mappings + mappings.json - settings + settings.json
And
@Document(indexName = "test", type="SentimentTweet") @Setting(settingPath = "/settings/settings.json") @Mapping(mappingPath = "/mappings/mappings.json")
However, in mappings.json, I should omit the field mappings and DIRECTLY put the content of the mapping.
INSTEAD OF:
{ "mappings": { "Tweet": { /* MAPPINGS CONFIGURATION ARE OMITTED */ } } }
Only writes in mappings.json:
{ "Tweet": { /* MAPPINGS CONFIGURATION ARE OMITTED */ } }
The same should be done for settings.json
这篇关于Spring-Data-Elasticsearch设置:Spring找不到配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!