Spring-Data-Elasticsearch settings: Spring can't find config file?

眉间皱痕 提交于 2019-11-28 11:50:09

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

The @Setting annotation should point to a file containing only the settings part. If you also want to specify your custom mapping, you need to use the @Mapping annotation and give it the path to your mapping file. It goes like this:

@Document(indexName = "test", type="Tweet")
@Setting(settingPath = "/settings/settings.json")
@Mapping(mappingPath = "/mappings/mappings.json")
public class Tweet {   

    @Id
    private String idStr;

    /** other fields, getters and setters are omitted **/

}

Then you need to store settings.json in myproject/src/main/resources/settings/ and mappings.json in myproject/src/main/resources/mappings/.

That should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!