Elastic search Nest - map update string property as not analysed

自作多情 提交于 2019-12-11 16:01:01

问题


I'm trying to map MyCode property in my object (posted down) as NotAnalyzed using fluent.

I've already reviewed: Creating an index Nest and Nest and Elastic Search - Mapping

{
  "myobject_test" : {
    "mappings" : {
      "myversion" : {
        "properties" : {
          "id" : {
            "type" : "long"
          },
          "isLatest" : {
            "type" : "boolean"
          },
          "maxVersion" : {
            "type" : "long"
          },
          "original" : {
            "properties" : {
              "agent" : {
                "properties" : {
                  "name" : {
                    "type" : "string"
                  },
                  "organizationId" : {
                    "type" : "long"
                  },
                  "version" : {
                    "type" : "long"
                  }
                }
              },
              "agentReference" : {
                "type" : "string"
              },
              "myCode" : {
                "type" : "string"
              },
              "myDate" : {
                "type" : "date",
                "format" : "dateOptionalTime"
              },
              "netWorth" : {
                "type" : "double"
              },
              "objectVersionId" : {
                "type" : "long"
              },
              "myOrganization" : {
                "properties" : {
                  "name" : {
                    "type" : "string"
                  },
                  "organizationId" : {
                    "type" : "long"
                  },
                  "version" : {
                    "type" : "long"
                  }
                }
              },
              "status" : {
                "type" : "long"
              }
            }
          },
          "version" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

This is how I tried: (do note original is type of BasicInformation)

 client.Map<MyVersion>(x => x
            .Properties(p => p.NestedObject<BasicInformation>(s => s.Name(n => n.Original)
                .Properties(pp => pp.String(ss => ss.Name(nn => nn.MyCode)
                    .Index(FieldIndexOption.NotAnalyzed))))));

I can't seem to find what i'm doing wrong...

ADDITIONAL INFO:

MyVersion class:

public class MyVersion : IMyVersion
{
    private int? _myVersionId;

    public int Id
    {
        get { return _myVersionId.HasValue ? _myVersionId.Value : Original.myVersionId; }
        set
        {
            _myVersionId = value;
        }
    }

    public int Version { get; set; }

    public int MaxVersion { get; set; }

    public BasicInformation Original { get; set; }

    [Obsolete("Used only for deserialization")]
    public MyVersion()
    {

    }

    internal MyVersion(BasicInformation original, int version, int maxVersion)
    {
        Original = original;
        Version = version;
        MaxVersion = maxVersion;
    }

    public bool IsLatest
    {
        get
        {
            return Version == MaxVersion;
        }
    }

    public bool Equals(IMyVersion other)
    {
        return other != null && Id.Equals(other.Id);
    }

}

Yes that json is after mapping. Also, I'm checking if mapping is correct with a test.

var mapping = ElasticClient.GetMapping<MyVersion>();
        var basicInformationMapping = mapping.Mappings[TEST_INDEX_NAME][0].Mapping.Properties[PropertyNameMarker.Create("original")] as
            ObjectMapping;
        var myCodeMapping =
            basicInformationMapping.Properties[PropertyNameMarker.Create("myCode")] as StringMapping;
        Assert.IsTrue(myCodeMapping.Index == FieldIndexOption.NotAnalyzed, "myCode field mapping index should be NotAnalyzed");

UPDATE:

     UpdateMapping(client, indexName);
     foreach (var myVersion in myVersions.Versions)
     {
         var version = myVersion;
         client.Index(myVersion, i => i.Id(version.Id).Index(indexName));
     }

来源:https://stackoverflow.com/questions/29519318/elastic-search-nest-map-update-string-property-as-not-analysed

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