有个人长的像洋葱,走着走着就哭了…….

mysql关联查询对应es怎么写呢

Elasticsearch | 作者 effort | 发布于2019年12月26日 | 阅读数:2270

es版本5.4.1

业务:查询产品线为1,2,3情况下 type不能为1的全部产品信息

对应sql:select * from tb_product where id not in (select id from tb_product where product_line in (1,2,3) and type=1)res
怎么写成es查询呢
已邀请:

dadaball

赞同来自:

我不確定5.4.1版可不可以這樣下
但是7版是可以,可以參考看看GET tb_product/_search
{
  "query": {
    "bool": {
      "must_not": [
         {
           "bool": {
             "must": [
              {"terms": {"product_line": [1,2,3]}},
              {"term": {"type": 1}}
            ]
          }
        }
      ]
    }
  }
}

liuxg - Elastic

赞同来自:

你可以参照一下官方文档:https://www.elastic.co/guide/e ... .html
 
must 和 must_not可以并排在一起
 
POST _search
{
  "query": {
    "bool": {
      "must": {
        "term": {
          "user": "kimchy"
        }
      },
      "filter": {
        "term": {
          "tag": "tech"
        }
      },
      "must_not": {
        "range": {
          "age": {
            "gte": 10,
            "lte": 20
          }
        }
      },
      "should": [
        {
          "term": {
            "tag": "wow"
          }
        },
        {
          "term": {
            "tag": "elasticsearch"
          }
        }
      ],
      "minimum_should_match": 1,
      "boost": 1
    }
  }
}

ppppenger

赞同来自:

POST /_sql/translate
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 10
}
 
translate API  https://www.elastic.co/guide/e ... .html

要回复问题请先登录注册