2

I'm new using Elastic Search, and i never used Lucene too.

I build this query:

  {
    "query" : {
      "wildcard" : { "referer" : "*.domain.com*" }
    },
    "filter" : {
      "query" : {
        "term" : { "first" : "1" }
      }
    },
    "facets" : {
      "site_id" : {
        "terms" : {
          "field" : "site",
          "size" : "70"
        }
      }
    }
  }

The wildcard is working great, but the term filter was ignored, what i did wrong?

I need to filter the results with both wildcard and term

Thanks!

rcmonteiro
  • 76
  • 1
  • 8
  • You have an added `"query"` around your `filter`ed `"term"`. Just cut that out and it should work. – pickypg Apr 13 '14 at 00:22

1 Answers1

2

Assuming what you are trying to do is applying the filter on the wildcard query results, you can use a FilteredQuery. However, your case might fit better for a filter.

You use a query filter. Instead of that you may directly use a TermFilter in a FilteredQuery rather than making a filter out of a TermQuery. TermFilter should be faster as it directly uses the TermsEnum.

Note that results of Filters are cached in a FilterCache and Filters are faster because they do not do any scoring of documents. In your case, even though the filter part of the FilteredQuery will work fast, but the wildcard query will be unnecessarily do scoring. You may try to use an AND Filter to club both queryfilter(wildcard query) and term filter instead of a FilteredQuery.

To make just the filter work as required by you, try something like below. (Not tried myself)

{
    "filtered" : {
        "query" : {
            "wildcard" : { "referer" : "*.domain.com*" }
        },
        "filter" : {
             "term" : { "first" : "1" }
        }
    },
    "facets" : {
        "site_id" : {
            "terms" : {
                "field" : "site",
                "size" : "70"
            }
        }
    }
}
Charlie Schliesser
  • 7,851
  • 4
  • 46
  • 76
aditrip
  • 304
  • 2
  • 3
  • i tried and i got this error: _No parser for element [filtered]_ Then i made a query wrap arround the filtered and everthing work great, i made the changes in the anwser, thanks! – rcmonteiro Apr 13 '14 at 13:37