0

I have a query string as follows:

query_body_text = {
    "from" : 0 ,
    "size": 7000,
    "query": {
    "query_string": {
      "query": "document_OrderName:(Mystuff) AND document_CreatedWhen:[2017-01-01T00:00:00.000+00:00 TO 2017-01-31T00:00:00.000+00:00]"
     }
   }
 }

I want to be able to search the field body_analysed for a regular expression in these documents

I know I can phrase this as below but how do I combine this with the query above for the field of interest?

"query": {
    "regexp": {
      "user.id": {
        "value": "k.*y",
        "flags": "ALL",
        "case_insensitive": true,
        "max_determinized_states": 10000,
        "rewrite": "constant_score"
      }
    }
  }

1 Answer 1

2

You can use a boolean query to combine both the query

should clause works like a logical OR operator and must clause works like a logical AND operator

{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "document_OrderName:(Mystuff) AND document_CreatedWhen:[2017-01-01T00:00:00.000+00:00 TO 2017-01-31T00:00:00.000+00:00]"
          }
        },
        {
          "regexp": {
            "user.id": {
              "value": "k.*y",
              "flags": "ALL",
              "case_insensitive": true,
              "max_determinized_states": 10000,
              "rewrite": "constant_score"
            }
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.