Search code examples
jsonamazon-web-servicesaws-elasticsearch

how to search data from amazon elastic search based on multiple conditions?


I have pushed JSON documents like below

{
"Apartment_Area": "marathahali",
 "Apartment_bhk": "2bhk",
 "Apartment_owner": "praveen",
 "Apartment_forSale": "sold_out"
}
{
 "Apartment_Area": "kadugodi",
 "Apartment_bhk": "1bhk",
 "Apartment_owner": "praveen",
 "Apartment_forSale": "for_sale"
}

now I am trying to search both 1bhk and 2 bhk from an elastic search using below query it gives me both 1 bhk and 2 bhk of JSON data.

/_search?pretty&q=1bhk,2bhk

Now I am trying to fetch 1 bhk with the name Praveen, which mean I only want to see the data of 1 bhk who's name is Praveen.

what would be the query for this any idea? Thanks in advance :)


Solution

  • Elasticsearch has pretty good documentation, have a look at the documentation here: Try a POST to /_search?pretty with the following body:

    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "terms" : {
                        "Apartment_bhk" : ["1bhk", "2bhk"]
                    }
                }
            }
        }
    }