Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Problem statement

Currently search uses filters which are joined with  AND ('&&') operator by default. Hence It is not possible to search with OR ('||') condition. Hence to search a user by either an email or phone number, It requires to make two different calls, one with phone and if result is empty then another call with email. This process is inefficient. Hence there should be a way that a user can be searched by email or phone. It requires to create a structure in filter where we need to provide if we want to call with and or or or both together.


Solution approach

Currently the filter request is mapped with elasticsearch request with 'must' call, which produces 'and' result. This should be modified to include 'must' or 'should' based on the filter structure provided. The filter should be able to use operators which can be mapped with 'and' or 'or' conditions.

Current filter

{
    "request": {
           "filters": {
                  "email" : "abc@example.com",
                  "phone" : "9988998899"
            }
      }
}

Above filter will fetch user whose email is abc@example.com and phone is 9988998899.

The changes for using or condition would be

{
  "request": {
    "filters": {
	"$or": [
	     {
	        "email" : "abc@example.com"
	     },
         {
            "phone" : "9988998899"
	     }
		]
    }
  }
}



basically a "$or" operator which takes an array of conditions to apply any of them.

This will have backward compatibility, since all the top level argument will be used as and condition as before

{
  "request": {
    "filters": {
		"$or": [
	     	{
	        	"email" : "abc@example.com"
	     	},
            {
                "phone" : "9988998899"
	     	}
		],
        "gender" : "male" 
    }
  }
}
  • No labels