ruby on rails - Elastic Search- Searching Multiple Queries in Single Field -


i'm new elastic search. have field name clearance in users table , i'm trying filter results based on this.

match: {           clearance: {             query: 'none',             type: 'phrase'           }         } 

when give above match query 3 results. i'm trying pass 1 more string along none. eg want find users clearance none , first level

i tried this.

multi_match: {               clearance: {                 query: 'none or first level',                 type: 'phrase'               }             } 

but ended in error. please help. correct me if question wrong.

one way making clearance not_analyzed field in mapping , using terms filter.

example:

put test {   "mappings": {     "e1":{       "properties": {         "clearance":{           "type": "string",           "index": "not_analyzed"         }       }     }   } } 

some test data:

put test/e1/1 {   "clearance":"none" } put test/e1/2 {   "clearance":"first level" } put test/e1/3 {   "clearance":"second level" } 

now query part:

get test/e1/_search {   "query": {     "filtered": {       "query": {         "match_all": {}       },       "filter": {         "terms": {           "clearance": [             "none",             "first level"           ],           "execution": "or"         }       }     }   } } 

result verfication:

{    "took": 1,    "timed_out": false,    "_shards": {       "total": 1,       "successful": 1,       "failed": 0    },    "hits": {       "total": 2,       "max_score": 1,       "hits": [          {             "_index": "test",             "_type": "e1",             "_id": "1",             "_score": 1,             "_source": {                "clearance": "none"             }          },          {             "_index": "test",             "_type": "e1",             "_id": "2",             "_score": 1,             "_source": {                "clearance": "first level"             }          }       ]    } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -