elasticsearch,Java,Curl,elasticsearch" /> elasticsearch,Java,Curl,elasticsearch" />

如何将ElasticSearch多重匹配搜索查询从cURL转换为JAVA?

如何将ElasticSearch多重匹配搜索查询从cURL转换为JAVA?,java,curl,elasticsearch,Java,Curl,elasticsearch,因此,在ES中创建(右)查询并使用sense插件对本地ES安装进行测试后,我现在面临的问题是:如何使用ES JAVA API从代码中执行同样的操作。以下是我试图翻译的问题: { "size": 5, "query": { "multi_match": { "query": "physics", "type": "most_fields", "fields": [ "document.title^10", "document.t

因此,在ES中创建(右)查询并使用sense插件对本地ES安装进行测试后,我现在面临的问题是:如何使用ES JAVA API从代码中执行同样的操作。以下是我试图翻译的问题:

{
"size": 5,
"query": {
  "multi_match": {
     "query": "physics",
     "type": "most_fields",
     "fields": [
         "document.title^10",
         "document.title.shingles^2",
         "document.title.ngrams",
         "person.name^10",
         "person.name.shingles^2",
         "person.name.ngrams",
         "document.topics.name^10",
         "document.topics.name.shingles^2",
         "document.topics.name.ngrams"
      ],
      "operator": "and"
    }
  }
}'
我知道应该是这样,但我不太确定:

 Node node = nodeBuilder().client(true).node();
    Client client = node.client();

    SearchResponse response = client.prepareSearch("dlsnew")
            .setTypes("person", "document")
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(QueryBuilders.multiMatchQuery("physics",
                    "document.title^10",
                    "document.title.shingles^2",
                    "document.title.ngrams",
                    "person.name^10",
                    "person.name.shingles^2",
                    "person.name.ngrams",
                    "document.topics.name^10",
                    "document.topics.name.shingles^2",
                    "document.topics.name.ngrams"))
            .setFrom(0).setSize(5).setExplain(true)
            .execute()
            .actionGet();

    SearchHit[] results = response.getHits().getHits();
另外,如何处理“运算符”和“类型”:“大多数字段”部分来自查询?

您几乎做到了

QueryBuilders.multiMatchQuery("physics",
                "document.title^10",
                "document.title.shingles^2",
                "document.title.ngrams",
                "person.name^10",
                "person.name.shingles^2",
                "person.name.ngrams",
                "document.topics.name^10",
                "document.topics.name.shingles^2",
                "document.topics.name.ngrams")
                .operator(MatchQueryBuilder.Operator.AND)
                .type(MultiMatchQueryBuilder.Type.MOST_FIELDS);