0

I'm reading my queries from my database and I add some filter in java side but the code doesn't work. I will read the part between stars from my database. Sorry for bad English. how can I make it work ,my query is:

{
  "from": 0,
  "size": 100,
  "query": {
    "filtered": **{
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "text": {
                  "query": "xxx",
                  "slop": 0
                }
              }
            },
            {
              "match": {
                "text": {
                  "query": "xbxxı",
                  "slop": 0
                }
              }
            }
          ],
          "minimum_should_match": 1,
          "boost": 1.0
        }
      }
    }**,
    "query": {
      "myFilter": {
        "filter": {
          "bool": {
            "must": [
              {
                "range": {
                  "date": {
                    "gt": "2015-09-08",
                    "lte": "2015-09-09"
                  }
                }
              },
              {
                "query": {
                  "match": {
                    "page": "1"
                  }
                }
              },
              {
                "range": {
                  "xxxx": {
                    "gt": "0.0"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}

1 Answer 1

1

The filtered you load from database is valid, however the problem is the query you define outside of ** .

"query": {
  "myFilter": {
    "filter": {
      "bool": {
        "must": [
          {
            "range": {
              "date": {
                "gt": "2015-09-08",
                "lte": "2015-09-09"
              }
            }
          },
          {
            "query": {
              "match": {
                "page": "1"
              }
            }
          },
          {
            "range": {
              "xxxx": {
                "gt": "0.0"
              }
            }
          }
        ]
      }
    }
  }
}

If you want to use this filter you have define it right after "query" inside your filtered.

{
"from": 0,
"size": 100,
"query": {
   "filtered":** {
      "query": {
        ...
      }**,
      "filter": {
         "bool": {
            "must": [
               {
                  "range": {
                     "date": {
                        "gt": "2015-09-08",
                        "lte": "2015-09-09"
                     }
                   }
                },
                {
                   "query": {
                       "match": {
                          "page": "1"
                        }
                    }
                 },
                 {  
                    "range": {
                       "xxxx": {
                          "gt": "0.0"
                        }
                    }
                 }
              ]
           }
         }
      }
   }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

I know that works like that. but the query I get from database is a formal query so the last paranthesis that has is closing the filtered part so filter will be placed out side of the query. I want a solution for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.