Rob
Rob

Reputation: 7216

Filtered search with Authorization for Elasticsearch

I'm trying to do a search where I look for "test" in any field while filtering for a specific client in the client_id field. Can't seem to figure this one out. This is how fat I got (but it's not working):

         {
              query: {
                  filtered: {
                      query: "test",
                      filter: {
                          term: {client_id: @client.id}
                      }
                  }
              }
          }

Upvotes: 0

Views: 81

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

This is the right syntax

{
 "query": {
   "filtered": {
     "query": {
       "match": {
         "_all": "test"
       }
     },
     "filter": {
       "term": {
         "client_id": @client.id
       }
     }
   }
 }
}

From ES Docs: The _all field allows you to search for values in documents without knowing which field contains the value

Upvotes: 1

Related Questions