【问题标题】:NEST Fluent DSL querying some URL fieldNEST Fluent DSL 查询一些 URL 字段
【发布时间】:2016-09-08 09:26:54
【问题描述】:

有一些与 NEST 相关的问题。以下是我的 ES 中的一些文档。

如您所见,我已经在我的 ES 中插入了一些条目。我试着做一些这样的查询:

        var response = elastic.Search<ESIntegrationLog>(s => s
                            .Index("20160806")
                            .Type("esintegrationlog")
                            .Query(q =>
                                q.Term(p => p.CalledBy, "lazada")
                            )
                            .Sort(ss => ss.Descending(p => p.CalledOn))
                            .Take(300)
                        );

结果和我预想的一样,我确实找到了入口。但是当我尝试通过'callPoint'查询时,我不知何故找不到任何结果。下面是代码:

        var response = elastic.Search<ESIntegrationLog>(s => s
                            .Index("20160806")
                            .Type("esintegrationlog")
                            .Query(q =>
                                q.Term(p => p.CallPoint, "/cloudconnect/api/xxxxxxx/v1")
                            )
                            .Sort(ss => ss.Descending(p => p.CalledOn))
                            .Take(300)
                        );

我已经尝试对 URL 进行编码,但仍然没有找到任何东西。有什么想法吗?

更新:我使用“匹配”解决了这个问题。

.Query(q =>
    //q.Term(p => p.CallPoint, "abcdefg")
    q.MatchPhrasePrefix(c=> c.Field(d=> d.CallPoint).Query("/cloudconnect/api/xxxxxxx/v1"))
)

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    我怀疑callPoint是一个已分析的string字段,已经被标准分析器分析过了。通过查看20160806 索引中的映射,您将能够看到callPoint 是如何映射的。使用Sense

    GET 20160806
    

    如果callPoint 的映射是{ "type" : "string" },那么将在索引时分析输入。您可以看到标准分析器将如何使用_analyze API 分析输入

    POST _analyze
    {
        "text" : "/cloudconnect/api/xxxxxxx/v1",
        "analyzer": "standard"
    }
    

    产生以下标记

    {
       "tokens": [
          {
             "token": "cloudconnect",
             "start_offset": 1,
             "end_offset": 13,
             "type": "<ALPHANUM>",
             "position": 0
          },
          {
             "token": "api",
             "start_offset": 14,
             "end_offset": 17,
             "type": "<ALPHANUM>",
             "position": 1
          },
          {
             "token": "xxxxxxx",
             "start_offset": 18,
             "end_offset": 25,
             "type": "<ALPHANUM>",
             "position": 2
          },
          {
             "token": "v1",
             "start_offset": 26,
             "end_offset": 28,
             "type": "<ALPHANUM>",
             "position": 3
          }
       ]
    }
    

    A term query 不分析查询输入,因此将尝试将查询输入与倒排索引中的内容进行匹配,对于callPoint 字段,已在索引时进行了分析。 A match query 确实会分析查询输入,因此您可以按预期获得文档的匹配项。或者,您可以将 callPoint 映射为 not_analyzed 字符串字段,以便在索引时不对输入进行分析,而是逐字进行索引。

    【讨论】:

    • 谢谢。对我帮助很大。
    • 不用担心,很高兴它有帮助:)
    猜你喜欢
    • 2021-11-15
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多