LiferayElasticSearch:使用StringQuery查询字段

watbbzwu  于 2022-12-11  发布在  ElasticSearch
关注(0)|答案(1)|浏览(119)

我需要使用query_string从ElasticSearch中查询两个字段:例如姓名和年龄。
如果我直接通过下面的Liferay的Elastic Search查询,它就可以工作:

{
  "query": {
    "bool": {
      "must": [ 
        { "match": { "recordSetId": "123" }}, 
        { "query_string": 
            { 
                "query": "Maximil*",
                "fields": ["name", "age"]
            }
        }
      ]
    }
  }
}

有人知道我如何从Liferay Java代码发送上述查询吗?我需要类似这样的东西:

StringQuery query = queries.string(searchTerms);
query.setFields(); // this does not exist...
twh00eeo

twh00eeo1#

SearchContext searchContext = new SearchContext();
searchContext.setStart(QueryUtil.ALL_POS);
searchContext.setEnd(QueryUtil.ALL_POS);
searchContext.setUserId(userId);
searchContext.setEntryClassNames("Enter the name of the class you want to get data from");

(Like()“日志文章.类.getName()”)

BooleanQuery query = new BooleanQueryImpl();
query.add(new TermQueryImpl("name", "Maximil*",BooleanClauseOccur.MUST);
query.add(new TermQueryImpl("age","Maximil*",BooleanClauseOccur.MUST);

Hits hits = IndexSearcherHelperUtil.search(searchContext, query);
List<Document> document = hits.toList();

相关问题