我有一个存储在嵌入式ES实例中的对象:

@Document(indexName = "users", type = "user")
public class Uer implements Serializable {

    @Id
    private String uid;

    @Field(type = FieldType.Nested, store = true, includeInParent = true)
    private LanguageValue name;

    @Data
    public static class LanguageValue {

        private String eng;

        private String deu;
    }
}

对于按名称搜索,我使用List<User> findByNameDeuContaining(String name);并传递由通配符包装的值。对于没有变音符号的名称,它可以正常工作,但是任何包含变音符号的名称我都没有结果。

错误或配置错误?

最佳答案

尝试使用带有分析器参数的@Field注释:

@Document(indexName = "lang")
public class Test {

    @Id
    @Field(type = FieldType.String, index = FieldIndex.no, store = false)
    private String id;

    @Field(type = FieldType.Nested)
    private LanguageValue namecustom;

}

class LanguageValue {

    @Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "standard", searchAnalyzer = "standard")
    private String en;

    @Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "de_std", searchAnalyzer = "de_std")
    private String de;
}

这给出了以下映射:
{
    "lang": {
        "mappings": {
            "test": {
                "properties": {
                    "id": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "namecustom": {
                        "type": "nested",
                        "properties": {
                            "de": {
                                "type": "string",
                                "analyzer": "de_std"
                            },
                            "en": {
                                "type": "string",
                                "analyzer": "standard"
                            }
                        }
                    }
                }
            }
        }
    }
}

关于elasticsearch - 搜索带有变音符号的字符串似乎不适用于Spring JPA ES,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44718406/

10-12 04:05