Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query DSL - Misunderstanding of filters

I have a query that looks like this:

{
  "query": {
    "constant_score": 
      "filter": {
        "missing": {
          "field": "parent_id"
        }
      }
  }
},
"size": limit,
"from": offset
}

My type has a parent_id and a wall_id field. How can I modify this query so that I can get all types that do not have a parent_id and do not have a wall_id? I can't seem to decipher it from the docs. Thanks for any help offered!

UPDATE

I have the following query that works, but I don't like the catchall query on the title. Is there a way to do this without having to add a "catchall?

{
  "query":{
  "filtered":{
     "query":{
        "field":{ "title":"*" }
     },
     "filter":{
        "and":{
           "filters":[
              {
                 "missing":{ "field":"parent_id" }
              },
              {
                 "missing":{ "field":"wall_id" }
              }
           ]
        }
     }
  }
 }, "size":10, "from":0
}
like image 897
swatkins Avatar asked Nov 29 '11 05:11

swatkins


People also ask

What is query DSL Elasticsearch?

Query DSLedit. Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses: Leaf query clauses.

What is bool query in Elasticsearch?

Boolean, or a bool query in Elasticsearch, is a type of search that allows you to combine conditions using Boolean conditions. Elasticsearch will search the document in the specified index and return all the records matching the combination of Boolean clauses.

What is bool query?

Boolean queryedit. A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery . It is built using one or more boolean clauses, each clause with a typed occurrence.


1 Answers

You're almost there, you just need to use the and filter under your constant_score query:

{
  "query": {
    "constant_score": {
      "filter": {
        "and":[
          { "missing":{ "field":"parent_id" }},
          { "missing":{ "field":"wall_id" }}
        ]
      }
    }
  }
}
like image 138
DrTech Avatar answered Oct 30 '22 09:10

DrTech