代码之家  ›  专栏  ›  技术社区  ›  WesleyHsiung

Elasticsearch term query as mysql in子句?

  •  0
  • WesleyHsiung  · 技术社区  · 6 年前

    在mysql中,我们可以查询为: select * from table1 where (name,age) in (('joe',11),('jim',15));

    如何在Elasticsearch中实现这一点?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Tania Petsouka    6 年前

    你需要把“应该”和“必须”结合起来。

    在这里阅读更多 https://www.elastic.co/blog/lost-in-translation-boolean-operations-and-filters-in-the-bool-query

    {
    "query": {
        "bool": {
            "should": [{
                "bool": {
                    "must": [{
                        "match": {
                            "name": "joe"
                        }
                    }, {
                        "match": {
                            "age": "11"
                        }
                    }]
                }
            }, {
                "bool": {
                    "must": [{
                        "match": {
                            "name": "jim"
                        }
                    }, {
                        "match": {
                            "age": "15"
                        }
                    }]
                }
            }]
        }
    }
    

    }