Bill Westfall
Bill Westfall

Reputation: 13

Elasticsearch combining queries

I've looked at the other examples on StackOverflow and on the Elastic site, but I cannot get this combined Elasticsearch query to work.

Individually projectName and timestamp queries work, but not this combined query:

curl -XGET "http://localhost/jenkins/_search/exists" -d'{"query" : {"bool": {"must": [{"match": {"data.projectName": {"query": "QA_Deployment","type": "phrase"}}}]},{"range": {"@timestamp": {"gte": "now-30d","lte": "now"}}}}}'

Upvotes: 1

Views: 85

Answers (1)

Jettro Coenradie
Jettro Coenradie

Reputation: 4733

I changed two things, there was a space missing between the -d', not sure if that is a problem though. The other thing is the second query. This should be within the bool>must part as well. This should work:

curl -XGET "http://localhost/jenkins/_search/exists" -d '
{
    "query" : {
        "bool": {
            "must": [
                {
                    "match": {
                        "data.projectName": {
                            "query": "QA_Deployment",
                            "type": "phrase"
                        }
                    }
                },
                {
                    "range": {
                        "@timestamp": {
                            "gte": "now-30d",
                            "lte": "now"
                        }
                    }
                }
            ]
        }
    }
}'

Upvotes: 1

Related Questions