Zlatan Omerovic
Zlatan Omerovic

Reputation: 4097

Simple elasticsearch query to get results by field value

I belive the problem is described in the question itself. I'm making a simple query:

GET /base/products

"body": {
  "query": {
    "filtered": {
        "filter": {
          "and": {
            "filters": [
              {
                "match": {
                  "userId": "10"
                }
              }
            ]
          }
        }
      }
    }
  }
}

But in the responses I get all the items from the database. Actually, I get that number of results provided in the "size" property.

I'm fairly new to elasticsearch so any help is very appreciated!

Upvotes: 0

Views: 48

Answers (1)

xeye
xeye

Reputation: 1256

You need term query, it matches exact value of a field:

{
  "query": {
    "term": {
      "userId": "10" 
    }
  }
}

Upvotes: 2

Related Questions