ES查询操作

1.通过multi_match进行多字段匹配查询

GET index_test/_search
{
  "query": {
    "multi_match": {
      "query": "测试",
      "fields": ["title","titleName"]
    }
  }
}

# java代码的实现
String[] field = new String[]{"title", "titleName"};
QueryBuilders.multiMatchQuery(param.getKeyWord(),field );

2.提高字段的权重查询

GET index_test/_search
{
  "query": {
    "multi_match": {
      "query": "测试",
      "fields": ["title^2","titleName^1"]
    }
  }
}

# java代码的实现
String[] field = new String[]{"title", "titleName"};
Map fields = new HashMap(2);
fields.put("company", 2.0f);
fields.put("titleName", 1.0f);
QueryBuilders.multiMatchQuery(param.getKeyWord(),field ).fields(fields);

你可能感兴趣的:(ES查询操作)