为什么使用 C#/ElasticSearch 进行此 NEST 通配符搜索时没有返回任何文档?

Why are no documents returned with this NEST wildcard search with C#/ElasticSearch?

此 NEST 通配符搜索返回零 (0) 个文档,尽管它应该返回零 (0) 个文档,因为我的索引中有符合此条件的数据。这是一个有效的连接,设置断点时没有错误显示。有什么想法吗?

public class Book_ES
{

    public string book_title { get; set; }
     public string book_author { get; set; }
}

 sr_detailed = new SearchDescriptor<Book_ES>()


                    .Index("books_3").Take(10000)
                   .Query(a => a
                          .Bool(b => b
                            .Should(c => c
                              .Wildcard(d => d
                                
 .Field(f=>f.book_title).Field(g=>g.book_author).Value("A*")
                              )
                            )
                          )
                        
                    ).Highlight(h => h.Fields(f => f.Field("*").PreTags("<span class='hit' style='background-color:yellow'>").PostTags("</span>")))
                   ;

 var results = Esclient.Search<Book_ES>(sr_detailed);

你没有分享你的地图,但我认为它看起来像

{
  "books_3": {
    "mappings": {
      "properties": {
        "book_title": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "book_author": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

在这种情况下,当您将 A* 作为通配符查询的值时,您不会得到任何返回结果,因为 book_titlebook_author 都使用标准分析器文本字段和所有大写字符都从索引标记中删除 - 对于此配置,elasticsearch 不会存储任何以 A 开头的标记,请参见下文

GET _analyze
{
  "analyzer": "standard",
  "text": "Test"
}

{
  "tokens" : [
    {
      "token" : "test",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "<ALPHANUM>",
      "position" : 0
    }
  ]
}

您可以在通配符查询中将 case_insensitive 设置为 true,这将解决您的问题 docs say

case_insensitive [7.10.0]Added in 7.10.0. (Optional, Boolean) Allows case insensitive matching of the pattern with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping.