0
votes

I need to search for something like this

POST dev_profiles/profiles/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "query_string": {
            "query": "user:asd"
          },
          "script_fields": {
            "message_age": {
              "script": {
                "source": "return doc.createdAt.value.getHour() == params.h",
                "params": {
                  "h": 9
                }
              }
            }
          }
        }
      ]
    }
  }
}

but can't build a query in the right way. Can somebody help?

In that case, it gives error [query_string] malformed query, expected [END_OBJECT] but found [FIELD_NAME] version of elasticsearch 6.8

1
can you add a sample data and what should be expected result?Akash jain

1 Answers

1
votes

The query you're looking for is like this:

{
  "query": {
    "bool": {
      "filter": [
        {
          "match": {
            "user": "asd"
          }
        }
        {
          "script": {
            "script": {
              "source": "return doc.createdAt.value.getHour() == params.h",
              "params": {
                "h": 9
              }
            }
          }
        }
      ]
    }
  }
}