2

I was able to use postfilters:

    POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "kimchy" }
          }
        }
       },
       "post_filter":{
            "terms" : { "tag" : ["tech", "luxury"] }
          },
       ...
    }

code to acomplish that query:

 SearchEngine searchEngine=SearchEngineHelperUtil
                                    .getSearchEngine(s_ctx.getSearchEngineId());
 IndexSearcher indexSearcher = searchEngine.getIndexSearcher();
 ...
 TermsFilter termsFilter = new TermsFilter("tag");
 termsFilter.addValue("tech");
 termsFilter.addValue("luxury");

 BooleanQuery booleanQuery = new BooleanQueryImpl(); //use factory instead
 ...
 booleanQuery.setPostFilter(termsFilter);
 indexSearcher.search(s_ctx, booleanQuery);
 ....
 //s_ctx is the searchContext

what i want is the query to be like in ElasticSearch doc:

   POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "kimchy" }
          },
          "filter": {
            "terms" : { "tag" : ["tech", "luxury"] }
          },
       ...
    }

How can i do that query in my custom Portlet using BoolQuery.class or something similar in liferay 7?

xistoso
  • 55
  • 6
  • 1
    That's an interesting question! Could you share the code which generated the first query? And why do you want the second one? – brandizzi Sep 06 '18 at 21:47
  • The Elastic documentation warning tells explicitly to not use for regular queries [source](https://www.elastic.co/guide/en/elasticsearch/guide/current/_post_filter.html): "Use a post_filter only if you need to differentiate filter search results and aggregations." and "The nature of the post_filter means it runs after the query, so any performance benefit of filtering (such as caches) is lost completely." – xistoso Sep 07 '18 at 14:53

0 Answers0