Is it possible to use facet script and facet filter in elasticsearch like this?

{
  "facets": {
    "judges": {
      "terms": {
        "field": "judges.untouched",
        "size": 10,
        "all_terms": false,
        "script": { "script": "...", "params": { }}
      },
      "global_facets": false,
      "facet_filter": {
        "and": [
          {
            "query": {
              "query_string": {
                "query": "..... ",
                "fields": [
                  "judges.analyzed"
                ],
                "default_operator": "and",
                "analyze_wildcard": true
              }
            }
          }
        ]
      }
    }
  }
}

Because when i run this query, elasticsearch raises error: Parse Failure [No facet type found for [and]]]; }.

Thanks

有帮助吗?

解决方案

EDIT Incorrect answer. I'm leaving it because of context. To clarify: and is an appropriate filter and should be accepted by facet_filter. Not sure what's up.

Untested, but from the docs: (http://www.elasticsearch.org/guide/reference/api/search/facets/)

All facets can be configured with an additional filter (explained in the Query DSL section)

So you need to put an appropriate query in facet_filter. And is NOT an appropriate filter (the error you receive could be clearer)

e.g:

"facet_filter" : {
   "term" : { "user" : "kimchy"}
} 

You'd probably want something like:

"facet_filter" : {
   "query_string": {
      "query": "..... ",
      "fields": [
         "judges.analyzed"
      ],
      "default_operator": "and",
      "analyze_wildcard": true
   }
}

其他提示

The syntax for an and filter is:

"facet_filter": {
  "and": {
    "filters": [
       {
         // filter definition
       },
       {
         // another filter definition
       }
    ]
  }
}

But you're using only a single condition, so there's no need of an and filter. You should just have:

   "facet_filter": {
     "query": {
       "query_string": {
         "query": "..."
       }
     }
   }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top