当复制mongo对象时,Elasticsearch返回“拒绝映射更新”,但是我不明白为什么

时间:2018-10-13 22:44:28

标签: mongodb elasticsearch nest

我遇到以下错误:

Rejecting mapping update to [test.pictures] as the final mapping would have more than 1 type: [_doc, pictureobject]

我了解这是与ES6相关的问题,如本博文所述:

Jest spyOn function called

但是,我不知道错误的来源:

我有一个名为PictureObject的mongo对象。该对象也与ES共享。

[Nest.ElasticsearchType, BsonIgnoreExtraElements]
public class PictureObject : DataStoreObject
{
    [Nest.Ignore]                           public string       OwnerId             { get; set; }
    [Nest.Ignore, BsonIgnoreIfDefault]      public string       AlbumId             { get; set; }
                                            public Flags        Flags               { get; set; }
    [Nest.Text, BsonIgnoreIfDefault]        public string       Title               { get; set; }
    [Nest.Text]                             public string       Tags                { get; set; }
    [Nest.Ignore]                           public int          Width               { get; set; }
    [Nest.Ignore]                           public int          Height              { get; set; }
    [Nest.Ignore]                           public string       Hash                { get; set; }
    [Nest.Number(Nest.NumberType.Integer)]  public int          VotesUp             { get; set; }
    [Nest.Ignore]                           public int          VotesDown           { get; set; }
    [Nest.Ignore]                           public int          Shows               { get; set; }
    [Nest.Number(Nest.NumberType.Integer)]  public int          Views               { get; set; }
    [Nest.Ignore, BsonIgnoreIfDefault]      public string       Link                { get; set; }
    [Nest.Ignore]                           public string       OriginUrl           { get; set; }
    [Nest.Ignore]                           public string       OriginTags          { get; set; }
    [Nest.Ignore, BsonIgnoreIfDefault]      public string       OriginTitle         { get; set; }
}

如您所见,该类以Mongo和ES属性装饰。

然后,我有了ES映射:

            var I = Client.CreateIndex(INDEX_NAME, Ci => Ci
                .Settings(S => S
                    .Analysis(A => A
                        .CharFilters(Cf => Cf.Mapping("expressions",
                            E => E.Mappings(
                                "test ab => testab",
                                "test bc => testbc"))
                        )
                        .TokenFilters(Tf => Tf.Synonym("synonyms",
                            Descriptor => new SynonymTokenFilter
                            {
                                Synonyms = new[]
                                {
                                    "syna1 => syna2, syna3",
                                    "synb1 => synb2, synb3"
                                },
                                Tokenizer = "whitespace"
                            })
                        )
                        .Analyzers(Analyzer => Analyzer
                            .Custom("index", C => C
                                .CharFilters("html_strip", "expressions")
                                .Tokenizer("standard")
                                .Filters("synonyms", "standard", "lowercase", "stop")
                            )
                            .Custom("search", C => C
                                .CharFilters("expressions")
                                .Tokenizer("standard")
                                .Filters("synonyms", "standard", "lowercase", "stop")
                            )
                        )
                    )
                )
                .Mappings(Mapping => Mapping
                    .Map<PictureObject>(Map => Map
                        .AutoMap()
                        .Properties(P => P
                            .Text(T => T
                                .Name(N => N.Title)
                                .Analyzer("index")
                                .SearchAnalyzer("search")
                            )
                            .Text(T => T
                                .Name(N => N.Tags)
                                .Analyzer("index")
                                .SearchAnalyzer("search")
                            )
                        )
                    )
                )
            );

我的目标是使mongo与ES之间具有1-1对应关系,所有更改均源自mongo。我希望在复制过程中忽略某些字段,并且希望能够在某些特定字段上使用同义词进行文本搜索。

我正在使用Monstache将mongo对象从oplog复制到ES。 在什么时候PictureObject项与_doc冲突?整个索引与类型之间的关系对我来说还不清楚,我看不出我在做什么或如何解决。

0 个答案:

没有答案