【问题标题】:How I can convert this SQL query to Elasticsearch query in Visual studio?如何在 Visual Studio 中将此 SQL 查询转换为 Elasticsearch 查询?
【发布时间】:2021-09-13 01:56:08
【问题描述】:

我是 Elasticsearch 查询的新手,所以我不知道如何在 Visual Studio 中将此 SQL 查询转换为 Elasticsearch 查询:

WHERE   
(x IS NOT NULL) AND (y IS NOT NULL) OR
(x IS NOT NULL) AND (z IS NOT NULL) OR
(x IS NOT NULL) AND (q IS NOT NULL) 

我知道 Elasticsearch 查询应该是这样的,带有“应该”和“必须”,但我确信它与正确的语法相去甚远,而且 Visual Studio 给了我太多的红线,上面写着“名称Must/Exist/Field 在当前上下文中不存在”。

             .Query(q => q
                    .Bool(m => m
                            .Should( s => s
                            .Must(
                         b => b.Exists(t => t.Field(y => y.x)),
                         b => b.Exists(t => t.Field(y => y.y))),

                            .Must(
                         b => b.Exists(t => t.Field(y => y.x)),
                         b => b.Exists(t => t.Field(y => y.z))),

                            .Must(

                         b => b.Exists(t => t.Field(y => y.x)),
                         b => b.Exists(t => t.Field(y => y.q))))

如果有人能帮助我找到将 SQL 查询转换为 Elasticsearch 的最佳方法,我将不胜感激。提前谢谢!

【问题讨论】:

    标签: c# sql visual-studio elasticsearch


    【解决方案1】:

    这是对我有用的答案,我喜欢与他人分享。

         .Query(q => q
             .Bool(m => m
                .Must(
                    b => b.Exists(t => t.Field(y => y.x)),
                    b => b.Bool(t => t
                       .Should(
                           b => b.Term(t => t.y, false),
                           b => b.Term(t => t.z, false),
                           b => b.Term(t => t.q, false))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      相关资源
      最近更新 更多