Querying from multiple indices

Hi All,

GET pk,dangal/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "user": "kimchy" }},
        { "match": {   "format": "text" }}
      ]
    }
  }
}

in the above query you can see that
In index pk had the term "user": "kimchy" in one document
in index dangal had the term "format": "text" in one document
now i want those two documents as output.......i must use AND condition

if i use should i am getting output but that checks OR condition

GET pk,dangal/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "user": "kimchy" }},
        { "match": {   "format": "text" }}
      ]
    }
  }
}

output

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 10,
    "successful": 10,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "pk",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.2876821,
        "_source": {
          "user": "kimchy",
          "post_date": "2009-11-15T14:12:12",
          "message": "trying out Elasticsearch"
        }
      },
      {
        "_index": "dangal",
        "_type": "_doc",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "user": "gilbert3",
          "post_date": "2010-11-15T14:12:12",
          "message": "trying out logstash",
          "format": "text"
        }
      }
    ]
  }
}

i want the same output with AND condition that is with must

I appreciate quick response

Thank You

I am not sure I understand. You do not have any document that matches both conditions you are looking for, which is why I assume the query with the must (AND) condition does not return anything.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.