0

Am new to elastic search, this is my query to find a exact match in my collection.

{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "_id": {
                  "query": "1"
               }
            }
         },      
       "filter": {
                "term" : {
                    "team_id":"2",
                    "created_user":"099"
                }
            }     
   }
   }
}

By running this query I am getting one record, but my problem is its not matching "team_id" filed. When I change team_id to some other value eg: 4, I am still getting the record with team_id = 2, Please help me to write an elastic search query with three fields. Thanks

3
  • If your _id field is unique, your query always returns one query. You are saying that Give me the result that has _id=1. Probably, this will return one result, it is not meaningful to filter this result then. It will be better, if you explain what are you trying to do Commented Mar 13, 2014 at 8:54
  • @HüseyinBABAL Thanks for quick reply, am new to elastic search my requirement in mysql way is select * from message where id = 1 and team_id = 2 and created_user = 099 Commented Mar 13, 2014 at 8:57
  • If you explain your request in real world(not in elasticsearch way), we can help you better Commented Mar 13, 2014 at 8:58

1 Answer 1

1

If you want exact match, be sure that fields that you want to make search operation must be not_analyzed. And it seems you are using multiple case in your filter. You can refactor your query by using and filter like;

{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "_id": {
                  "query": "1"  // remember that, this will always return one result. Update here according to your needs. For example, use tag instead of _id like tag=responsive in order to get results that matches tag field with responsive
               }
            }
         },      
       "filter": {
            "and": [
                {
                  "term": {"team_id":"2"}
                },
                {
                  "term": {"created_user":"099"}
                }
            ]
        }     
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.