GET /hotel/_search
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "如家",
"fields": ["name", "brand"]
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"fields": {
"name": {},
"brand": {}
},
"pre_tags": "<span style=\"color: red\">",
"post_tags": "</span>"
}
}
kibanay请求时:高亮
GET /hotel/_search
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "如家",
"fields": ["name", "brand"]
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"fields": {
"name": {},
"brand": {}
},
"pre_tags": "<span style=\"color: red\">",
"post_tags": "</span>"
}
}
package com.hr.hotel.constants;
public class HotelIndexConstants {
public static final String SERVER_URL = "http://49.232.192.152:9200";
//
public static final String MAPPING_HOTEL = "{\n" +
" \"mappings\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"keyword\"\n" +
" },\n" +
" \"name\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"copy_to\": \"all\"\n" +
" },\n" +
" \"address\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": false\n" +
" },\n" +
" \"price\": {\n" +
" \"type\": \"integer\"\n" +
" },\n" +
" \"score\": {\n" +
" \"type\": \"integer\"\n" +
" },\n" +
" \"brand\": {\n" +
" \"type\": \"keyword\",\n" +
" \"copy_to\": \"all\"\n" +
" },\n" +
" \"city\": {\n" +
" \"type\": \"keyword\"\n" +
" },\n" +
" \"starName\": {\n" +
" \"type\": \"keyword\"\n" +
" },\n" +
" \"business\": {\n" +
" \"type\": \"keyword\",\n" +
" \"copy_to\": \"all\"\n" +
" },\n" +
" \"pic\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": false\n" +
" },\n" +
" \"location\": {\n" +
" \"type\": \"geo_point\"\n" +
" },\n" +
" \"all\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
}
SpringBoot启动类
@SpringBootApplication
@MapperScan("com.hr.hotel.mapper")
public class HotelApplication {
public static void main(String[] args) {
SpringApplication.run(HotelApplication.class, args);
}
@Bean
RestHighLevelClient restHighLevelClient() {
return new RestHighLevelClient(
RestClient.builder(
new HttpHost(HotelIndexConstants.SERVER_URL, 9200, "http")));
}
}