How to check for 1 of 2 fields to exist in record

I am having an issue getting a result where 1 or 2 fields exist. either is fine but the best I can figure is how to require both using the below query for ES6.5.

{
  "version":"2017-02-28",
  "operation":"GET",
  "path":"/articlesnew1/json/_search",
  "params":{
    "body": {
      "size": 50,
      "query": {
        "bool": {
          "should" : [
            {
              "terms" : {
                "field_categories.__target_path" : ["he/taxonomy_term/categories/837","he/taxonomy_term/categories/840","he/taxonomy_term/categories/841","he/taxonomy_term/categories/842"]
              }
            },
            {
              "terms" : {
                "field_plays.__target_path" : ["he/taxonomy_term/plays/757","he/taxonomy_term/plays/758","he/taxonomy_term/plays/759","he/taxonomy_term/plays/761","he/taxonomy_term/plays/762"]
              }
            } 
          ],
          "must_not": [
            {
              "term": { 
              	"field_exclude_from_syndication.value": 1 
              }
            }
          ],
          "must": [
            {
              "bool": {
                "should" : [{
                  "exists": {
                    "field" : "field_categories.__target_path"
                  },
                  "exists": {
                    "field" : "field_plays.__target_path"
                  }
                }]
              }
            }
          ],
          "filter": [
            {
              "terms": {
                  "entity.bundle" : ["he_activity_highlight","he_company","he_event","he_exclusive","he_industry_voice","he_new_financing","he_news"]
               }
            },
            {
              "range" : {
                "entity.changed.timestamp" : {
                  "gte": "${context.arguments.from}",
                  "lte": "${context.arguments.to}"
                }
              }
            }
          ]
        }
      }
    }
  }
 }

My records may have values like this

"field_categories": [
     {
         "__target_path": "he/taxonomy_term/categories/878"
     }
 ],

 "field_plays": [
     {
         "__target_path": "he/taxonomy_term/plays/776"
     }
 ],

But not all data has both some have one some have the other. I need to return them as well as records that have both values present.

Ideas?

You are missing a couple of { } in the should clause around exists:

              [
                {
                  "exists": {
                    "field" : "field_categories.__target_path"
                  },
                  "exists": {
                    "field" : "field_plays.__target_path"
                  }
                }
              ]

I think it should be

              [
                {
                  "exists": {
                    "field" : "field_categories.__target_path"
                  }
                },
                {
                  "exists": {
                    "field" : "field_plays.__target_path"
                  }
                }
              ]

Great eye!. that did it!

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