Search code examples
djangoelasticsearchkibanaelasticsearch-dslelasticsearch-query

Getting all values of 2 columns


I am looking for appropriate elasticsearch query for,

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

eg: This is my mapping,

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

I am trying to write a query which will give me price and name which has booktype=Fiction


Solution

  • Try this:

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

    Note: you might need to adapt "size" to fit your needs.