首页 > 解决方案 > 获取 2 列的所有值

问题描述

我正在寻找合适的弹性搜索查询,

SELECT col1,col2 FROM myTable WHERE col1="value1" AND col2 = "value2"

例如:这是我的映射,

{
    "mapping": {
        "doc": {
            "properties": {
                "book": {
                    "properties": {
                        "name": {
                            "type": "text"
                        },
                        "price": {
                            "type": "integer"
                        },
                        "booktype": {
                            "properties": {
                                "booktype": {
                                    "type": "text"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

我正在尝试编写一个查询,它会给我price并且namebooktype=Fiction

标签: djangoelasticsearchkibanaelasticsearch-dslelasticsearch-query

解决方案


试试这个:

GET myTable/_search
{
  "size": 1000,
  "_source": [
    "price",
    "name"
  ],
  "query": {
    "bool": {
      "must": [
        {
           "match": {
             "booktype.booktype": "Fiction"
           }
        }
      ]
    }
  }
}

注意:您可能需要调整“大小”以满足您的需求。


推荐阅读