我试图为多语言目的索引multiField String属性(“prueba”)。我的映射正在使用注释
@MultiField(
mainField = @Field(type = FieldType.String, store = true),
otherFields = {
@NestedField(dotSuffix = "cat", type = FieldType.String, store = true, indexAnalyzer = "catalan", searchAnalyzer = "catalan" ),
@NestedField(dotSuffix = "ba", type = FieldType.String, store = true, indexAnalyzer = "basque", searchAnalyzer = "basque"),
@NestedField(dotSuffix = "gal", type = FieldType.String, store = true, indexAnalyzer = "galician", searchAnalyzer = "galician"),
@NestedField(dotSuffix = "en", type = FieldType.String, store = true, indexAnalyzer = "english", searchAnalyzer = "english")}
)
protected String prueba;
结果映射是:
,
"prueba": {
"type": "string",
"store": true,
"fields": {
"prueba.ba": {
"type": "string",
"store": true,
"analyzer": "basque"
},
"prueba.cat": {
"type": "string",
"store": true,
"analyzer": "catalan"
},
"prueba.en": {
"type": "string",
"store": true,
"analyzer": "english"
},
"prueba.gal": {
"type": "string",
"store": true,
"analyzer": "galician"
}
}
},
所以,我索引我的对象但结果只是......`
IndexQuery query = new IndexQuery();
query.setObject(itemTransparencia);
query.setType(subportal);
String id = this.elasticsearchOperations.index(query);
GET /item_transparencia/432/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "item_transparencia",
"_type": "432",
"_id": "AVTxEfvBhgYXtMQTaKx1",
"_score": 1,
"_source": {
"subportal": "432",
"titulo": null,
"prueba": "prueba la tarta de mi casa",
"subTitulo": null,
"descripcion": null,
"fechaIndexado": "2016-05-
我只能“prueba”:“prueba la tarta de mi casa”。
- 有人帮我理解如何索引或从字段“prueba”获取嵌套字段? - indexAnalyzer =“catalan”,searchAnalyzer =“catalan”帮我自动索引到另一个语言?
非常感谢!
答案 0 :(得分:1)
多字段prueba.ba
,prueba.cat
,prueba.en
,prueba.gal
已被编入索引,但您不会在源文档中看到它们。
您现在可以直接在查询中引用它们(映射中声明的分析器将按预期使用),您将获得预期的结果。例如,以下查询应返回标识为AVTxEfvBhgYXtMQTaKx1
的文档。
{
"query": {
"match": {
"prueba.ba": "prueba"
}
}
}
但是,请注意,在字段上设置语言分析器不会将字段的内容转换为该分析器的语言,您需要自己完成。