【问题标题】:Elastic search (using NEST) returns 0 results on MatchAll()弹性搜索(使用 NEST)在 MatchAll() 上返回 0 个结果
【发布时间】:2019-11-08 17:15:09
【问题描述】:

我正在使用以下代码在 .net 核心应用程序中使用 NEST 来索引文档和测试结果。 但它没有返回任何记录。

所以要么我做错了索引,要么我有查询问题。

弹性搜索非常新。所以不知道下面的代码有什么问题,因为我正在尝试索引文本文件的文本并搜索它进行测试。

private static void Index()
        {
            var settings = new ConnectionSettings().DefaultIndex("ProjectDocuments");

            var client = new ElasticClient(settings);

            //First, you need to make the routing required when you are creating your index, like this:
            client.CreateIndex("ProjectDocuments", d => d 
                .Mappings(mapping => mapping
                .Map<Document>(map => map
                .RoutingField(routing => routing
                .Required(true))
                .AutoMap())
            ));

            Routing routingFromInt = 1;

            Document document = new Document()
            {
                Id = 1,
                Content = "Some Text File Text"
            };

            IIndexResponse result = client.Index<Document>(document, selector => selector
                .Id(1)
                .Routing(routingFromInt));

            //TODO: Following returns 0. so might be issue with indexing itself.
            ISearchResponse<Document> searchResponse = client.Search<Document>(query => query.Query(q => q.MatchAll()).Routing(routingFromInt));

            var documents = searchResponse.Documents;
        }

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    问题在于默认索引名称。弹性搜索中不支持大写的索引名称

    所以“ProjectDocuments”引起了问题。将其更改为“project_documents”并开始工作。

    【讨论】:

    • 您可以检查任何响应上的.IsValid,以了解请求/响应是否有效。这是一个 NEST 构造
    • 哦。有帮助。谢谢。
    猜你喜欢
    • 2018-11-07
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2016-12-09
    • 2012-03-06
    • 1970-01-01
    相关资源
    最近更新 更多