嵌套和弹性搜索-更新嵌套对象的映射? [英] Nest and elastic search- update mapping for nested object?

查看:81
本文介绍了嵌套和弹性搜索-更新嵌套对象的映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将新属性添加到现有的嵌套文档中.我的文档如下:

I am trying to add a new property to an existing nested document. My document looks like:

"mappings": {
  "test": {
    "_routing": {
      "required": true,
      "path": "tId"
    },
    "properties": {

      "series": {
        "type": "nested",
        "properties": {

          "iType": {
            "type": "string",
            "index": "not_analyzed",
            "doc_values": true
          },
          "isValid": {
            "type": "boolean"
          },

        },
      },
    }
  }

我要插入到嵌套文档系列"中的属性是"iType". 我如何使用NEST put mapping API是否可以更新现有映射?

The property i want to insert to nested document "series" is "iType". How can i use the NEST put mapping API to update the existing mapping?

任何帮助将不胜感激.

谢谢.

##### ***** UPDATED ***** ##########

我需要使用属性更新嵌套元素的映射:

i would need to update the mapping for nested element with attributes :

"iType": {
  "type": "string",
  "fields": {
    "raw": {
      "type": "string",
      "index": "not_analyzed",
      "doc_values": true,
      "fielddata": {
        "loading": "eager_global_ordinals"
      }
    }
  }
},

我如何使用NEST做到这一点?

How can i do this with NEST ?

我的查询如下:

var response2 = elasticClient.Map < Test > (e => e
  .Properties(props => props
    .NestedObject < series > (s => s
      .Properties(sprops => sprops
        .String(n => n.Name(name => "iType"))))));

我遇到一个异常:无法获取嵌套sobject映射的字段名称 在查询中需要进行任何更正吗?

i get an exception: Could not get field name for nested sobject mapping Any corrections to be made in query?

推荐答案

您可以通过以下方式更新嵌套对象的映射:

You can update mapping for nested object by

var response = client.Map<YourType>(m => m
    .Properties(p => p
        .NestedObject<YourNestedType>(n => n
            .Name(name => name.NestedObject)
            .Properties(pp => pp
                .String(s => s.Name(name => name.NewProp))
            ))));

更新

这是通过 multi来更新索引映射的方法字段:

var response = client.Map<Test>(m => m
    .Properties(p => p
        .NestedObject<Series>(nested => nested
            .Name(name => name.Series)
            .Properties(pp => pp
                .MultiField(mf => mf
                    .Name(name => name.iType)
                    .Fields(f => f 
                        .String(s => s.Name(n => n.iType))
                        .String(s => s
                            .Name(n => n.iType.Suffix("raw"))
                            .Index(FieldIndexOption.NotAnalyzed)
                            .DocValues()
                            .FieldData(fd => fd
                                .Loading(FieldDataLoading.EagerGlobalOrdinals))))))
            ))); 

您遇到了一个例外,因为您没有为嵌套对象指定名称,请再看一下我的映射定义:

You got the exception, because you didn't specify name for nested object, take a look one more time at my mapping definition:

希望有帮助.

这篇关于嵌套和弹性搜索-更新嵌套对象的映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆