request resolver with es...trying to limit filter results

0

I have a query like this...

{
  "version":"2017-02-28",
  "operation":"GET",
  "path":"/articlesnew1/json/_search",
  "params":{
    "body": {
      "size": 50,
      "query": {
        "bool": {
          "should" : [
          	{
              "exists" : {
                "field" : "field_categories.__target_path"
              }
            },
            {
              "exists" : {
                "field" : "field_plays.__target_path"
              }
            },
            {
              "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""]
              }
            } 
          ],
          "must_not": [
            {
              "term": { 
              	"field_exclude_from_syndication.value": 1 
              }
            }
          ],
          "filter": [
          	{
              "terms": {
                  "entity.bundle" : ["he_activity_highlight","he_company","he_event","he_exclusive","he_industry_voice","he_new_financing","he_news","he_opinion","he_person","he_publication","he_transaction","he_under_40","he_whos_who"]
               }
            },
            {
              "range" : {
                "entity.changed.timestamp" : {
                  "gte": "${context.arguments.from}",
                  "lte": "${context.arguments.to}"
                }
              }
            }
          ]
        }
      }
    }
  }
}

But I do not want results where either "field_categories.__target_path" or "field_plays.__target_path" are not present and matching one of the values. But I am still getting results where both are empty like this...

"field_categories": [],
"field_plays": [],

The expected results might look like this...
"field_categories": [{
"__target_path": "he/taxonomy_term/categories/850"
}],

...or this...
"field_plays": [{
"__target_path": "he/taxonomy_term/plays/772"
}],

ideas?

Edited by: cjokinen on Jun 10, 2019 2:30 PM

Edited by: cjokinen on Jun 10, 2019 2:31 PM

Edited by: cjokinen on Jun 10, 2019 2:32 PM

asked 5 years ago208 views
2 Answers
0

UPDATE: I changed my code to what is below, but it is too restrictive and only returns records that have both the category and play flelds. I need it to return records if both or either field exist.

{
  "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","he/taxonomy_term/plays/763","he/taxonomy_term/plays/764"]
              }
            } 
          ],
          "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","he_opinion","he_person","he_publication","he_transaction","he_under_40","he_whos_who"]
               }
            },
            {
              "range" : {
                "entity.changed.timestamp" : {
                  "gte": "${context.arguments.from}",
                  "lte": "${context.arguments.to}"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Ideas?

Edited by: cjokinen on Jun 11, 2019 9:33 AM

Edited by: cjokinen on Jun 11, 2019 9:34 AM

answered 5 years ago
0

I found the answer in that I missed some curly braces inside of the must section....

{
  "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","he/taxonomy_term/plays/763","he/taxonomy_term/plays/764"]
              }
            } 
          ],
          "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"]
               }
            },
            {
              "range" : {
                "entity.changed.timestamp" : {
                  "gte": "${context.arguments.from}",
                  "lte": "${context.arguments.to}"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Edited by: cjokinen on Jun 11, 2019 1:21 PM

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions