0

i am trying to run a script with query filter. the script should return me all books with title gt 30:

GET books/_search
{
    "filter" : {       
          "script" : {
              "script" : "_source.title?.length() > 30"
          }
      }
}

this works.

but if i try to add some filter, like i want all the books that not has 'type' field :

GET book/_search
{
    "filter" : {        
          "script" : {
              "script" : "_source.title?.length() > 30"
          },
          "missing" : { "field" : "type" },
      }
}

then i get error:

nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"exists\"]; }]

so i can i query for missing fields with script filter?

1 Answer 1

2

You're on the right track, you simply need to combine both of your filters into a bool/must query.

POST book/_search
{
  "filter": {
    "bool": {
      "must": [
        {
          "script": {
            "script": "_source.title?.length() > 30"
          }
        },
        {
          "missing": {
            "field": "type"
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

bool/must is just one example, there are more "Compound query clauses": elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl.html
Yes, eventually dis_max, indeed.

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.