ElasticSearch应该查询

时间:2018-10-15 10:44:02

标签: elasticsearch

我想创建与该SQL查询相同的ElasticSearch查询

select *
from main.adverts
where user_id = 4
      and 
      (title ilike '%продать / купить%'
        or description ilike '%продать / купить%'
      )

我的尝试是:

{
  "query" :{
  "bool" : {
    "must" : [
      {
        "term" : {
          "user.id" : {
            "value" : 4,
            "boost" : 1.0
          }
        }
      }
    ],
    "should" : [
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "title" : {
                  "query" : "продать",
                  "operator" : "OR",
                  "fuzzy_transpositions" : false,
                  "boost" : 1.0
                }
              }
            },
            {
              "wildcard" : {
                "title" : {
                  "wildcard" : "купить*",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "description" : {
                  "query" : "продать",
                  "operator" : "OR",
                  "fuzzy_transpositions" : false,
                  "boost" : 1.0
                }
              }
            },
            {
              "wildcard" : {
                "description" : {
                  "wildcard" : "купить*",
                  "boost" : 1.0
                }
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "disable_coord" : false,
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
}

但是它不能正常工作。作为此查询的结果,我得到了不包含短语“продать/купить”的记录。

我认为问题出在ElasticSearch查询的“应该”部分,但无法确定具体位置。

你能指出我的错误在哪里吗?

1 个答案:

答案 0 :(得分:0)

似乎我找到了解决方法

FieldInfo.SetValue(...)