elasticsearch, documents with data in field1 OR field2 -


how instruct elasticsearch return documents have data in 1 of following fields: ['field1','field2']?

i have tried:

{ 'query': {     'bool':{         'must':[             'multi_match':{                 'fields':['field1','field2'],                      'operator':'and',                      'tie_breaker':1.0,                      'query': '*',                      'type':'cross_fields'                  }              ]          }      } } 

i tried:

{     "query":{         "wildcard":             {                  "field1":"*"             }         } } 

which works, but:

{     "query":{         "wildcard":             {                  "field*":"*"             }         } } 

does not

you can 2 exists filters in bool filter

as example, set simple index , gave data:

put /test_index  post /test_index/doc/_bulk {"index":{"_id":1}} {"field1":"foo","field2":"bar"} {"index":{"_id":2}} {"field2":"foo","field3":"bar"} {"index":{"_id":3}} {"field3":"foo","field4":"bar"} {"index":{"_id":4}} {"field4":"foo","field5":"bar"} 

if want find documents have "field1" or "field3", can this:

post /test_index/_search {    "query": {       "filtered": {          "query": {             "match_all": {}          },          "filter": {             "bool": {                "should": [                   { "exists": { "field": "field1" } },                   { "exists": { "field": "field3" } }                ]             }          }       }    } } 

it returns expect:

{    "took": 1,    "timed_out": false,    "_shards": {       "total": 1,       "successful": 1,       "failed": 0    },    "hits": {       "total": 3,       "max_score": 1,       "hits": [          {             "_index": "test_index",             "_type": "doc",             "_id": "1",             "_score": 1,             "_source": {                "field1": "foo",                "field2": "bar"             }          },          {             "_index": "test_index",             "_type": "doc",             "_id": "2",             "_score": 1,             "_source": {                "field2": "foo",                "field3": "bar"             }          },          {             "_index": "test_index",             "_type": "doc",             "_id": "3",             "_score": 1,             "_source": {                "field3": "foo",                "field4": "bar"             }          }       ]    } } 

here's code used:

http://sense.qbox.io/gist/991b828de250e5125fd372bf7e6b066acec55fcd


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -