0

我正在将我的 Elasticsearch 项目从 v6.6 升级到 v7.6.2。我使用 Elasticsearch.NET 和 NEST 来创建我的索引,包括映射、设置,并将我的数据从我的 SQL 数据库中提取到 Elasticsearch 中。

在 v6.6 中一切正常,但是当我升级到 v7.6.2 时,它不再接受我的自定义映射和设置。我指的是我的嵌套对象、我的自定义分析器等。数据确实被摄取,但它默认为默认映射(其中大部分都是关键字或简单数据类型)。

当您的映射或 POCO 中存在语法错误时,通常会发生这种类型的行为。这不是我的情况,我不认为。

v7.x 中是否有一些我可能错过的重大变化?我已经相当广泛地阅读了文档。

为了举例说明我的映射应该是什么样子,这里有一段摘录(来自我的 v6.6 集群)。

...注意“产品”对象之类的类型:嵌套...

[{"searchdata":{"_all":{"enabled":false},"properties":{"groupid":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"products":{"type":"nested","properties":{"adddate":{"type":"date"},"additionaltitles":{"type":"text"},"additionaltitleslist":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"adult":{"type":"integer"},"artists":{"properties":{"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"name":{"type":"text","norms":false,"fields":{"ci":{"type":"text","norms":false,"analyzer":"caseInsensitive"},"nc":{"type":"text","norms":false,"analyzer":"titleNoCharAnalyzer"},"raw":

这是它在 v7.6.2 中显示为默认版本的内容...

...注意诸如“产品”对象未嵌套,大量“关键字”类型,没有自定义分析器等...

    [{"_doc":{"properties":{"groupid":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"products":{"properties":{"adult":{"type":"long"},"artists":{"properties":{"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"nameidsplit":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"nameremarticle":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"catalognum":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"costprice":{"type":"float"},"cover":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"credits":{"properties":{"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"nameidsplit":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"nameremarticle":{"type":"text","fields":

您可能会注意到,v6.6 版本更详细,包含我的嵌套对象等。但我的 v7.6.2 版本包含基本的默认结构。

这里一定有问题,但我不知道是什么。

是否有一些我可以启用的调试日志记录级别会告诉我为什么它“失败”?

更新 所以我在这里放了一个稍微简略的版本来说明我如何映射我的对象和设置。希望这有助于理解这个问题。

var indexCreate = client.Indices.Create(indexName, nc => nc
.Settings(st => st
    .RefreshInterval(60) //slowing the refresh interval so we can get a running count
    .NumberOfReplicas(0) //must be set to refresh after created
    .NumberOfShards(numOfShards)
    .Analysis(a => a
        .Analyzers(an => an
            .UserDefined("fullTermCaseInsensitive", FullTermCaseInsensitive)
            .UserDefined("fullTerm", FullTerm)
            .UserDefined("caseInsensitive", CaseInsensitive)                      
        )
        .TokenFilters(tf => tf
            .UserDefined("syn", Syn)
            .UserDefined("myStopFilter", MyStopFilter)
            .UserDefined("wordDelimiter", WordDelimiter)                           
        )
    )
)
.Map<Store24>(m => m
    .Dynamic(false)

    .AutoMap()
    .Properties(props =>
    {
        SetPutMappingStore24(props); //see function below
        return props;
    })
));
       private static void SetPutMappingStore24(PropertiesDescriptor<Store24> pm)
       {
            pm.Nested<Product>(x => x
                .AutoMap()
                .Name(nm => nm.Products)
                .Properties(pr => pr
                    .Nested<StorePriceSplit>(sp => sp
                        .Name("storeprice").AutoMap()
                    )
                .Properties(props =>
                    {
                        SetPutMappingDescriptorTiWo(props, "tracks");
                        SetPutMappingDescriptorTiWo(props, "title");
                    }
                )
           );

       //...... more fluent mappings here
       }
    [ElasticsearchType(IdProperty = "Groupid")]
    public class Store24
    {
        /// <summary>
        /// Identifiers
        /// </summary>
        [Key]
        [Keyword]
        public string Groupid { get; set; }

        [JsonIgnore]
        public string Upc { get; set; }

        [JsonIgnore]
        public string Titleremarticle { get; set; }

        [Nested]
        [PropertyName("products")]
        public IEnumerable<Product> Products { get; set; }

    //... more properties here
    }
    [ElasticsearchType(RelationName = "product")]
    public class Product
    {
        [Key]
        [Text(Analyzer = "fullTermCaseInsensitive")]
        public string Upc { get; set; }

        [Text(Analyzer = "fullTermCaseInsensitive", Fielddata = true)]
        public string Titleremarticle { get; set; }

    //...more properties here
    }

我使用了两个对象,一个名为Store24的对象映射自 SQL 返回的数据,另一个对象名为Product,它创建 Elasticsearch 映射。

4

1 回答 1

0

我想出了我自己的问题。似乎索引的创建引发了错误,但我没有看到它。它被对 Indices.Create() 返回对象的响应“隐藏”了。(上面示例中的 var indexCreate 对象)。一旦我戳它,就会抛出以下错误:“令牌过滤器 [wordDelimiter] 不能用于解析同义词”。

这是我的设置中的一个问题 - 我猜想 7.x 的重大变化是我没有看到的。实际上是一个相当复杂的问题。

于 2020-04-06T21:19:31.327 回答