0

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));
     }
Community
  • 1
  • 1
rexdefuror
  • 573
  • 2
  • 13
  • 33
  • I tried your fluent mapping and it's working with ES 1.4.0 and NEST 1.4.3. This json mapping is what you get after applying `client.Map<...>`? May you share your `MyVersion` class? – Rob Apr 08 '15 at 16:31
  • Additional info supplied – rexdefuror Apr 08 '15 at 17:19
  • Which version of NEST and ES do you use? – Rob Apr 08 '15 at 17:47
  • It is possible that you indexed some data and then you changed mapping? Can you check response from `client.Map(..)`? – Rob Apr 09 '15 at 08:54
  • Yeah I did, this is in UpdateMapping method. Does that make a difference? – rexdefuror Apr 09 '15 at 09:12
  • Yes, this blog post will explain you why https://www.elastic.co/blog/changing-mapping-with-zero-downtime. Most of the time you should reindex data after mapping change. – Rob Apr 09 '15 at 09:18
  • OK my bad here, I actually don't index anything before this, this is last step before it. I've updated the question with what's doing on. – rexdefuror Apr 09 '15 at 11:15

0 Answers0