能够使用单个查询字段从单个索引中获取文档。请找到以下代码。
SearchRequest searchCatalogValueRequest = new SearchRequest(CATALOG_INDEX);
SearchSourceBuilder catalogSearchSourceBuilder = new SearchSourceBuilder();
searchCatalogValueRequest.types(TYPE);
QueryBuilder qb1 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("catalog_value", keyword))
.filter(QueryBuilders.termQuery("locale", USER_LOCALE));
但是现在,我想从具有两个查询字段的两个索引中获取文档。像下面的代码片段。
SearchRequest searchCatalogValueRequest = new SearchRequest(CATALOG_INDEX, PRODUCT_INDEX);
SearchSourceBuilder catalogSearchSourceBuilder = new SearchSourceBuilder();
searchCatalogValueRequest.types(TYPE);
QueryBuilder qb1 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("catalog_value", keyword)) // here i want to search with product_value field also.
.filter(QueryBuilders.termQuery("locale", USER_LOCALE));
我想在catalog_value
和product_value
的两个字段中查询。不确定如何实现。
请找到我的地图详细信息 产品字段映射
PUT product
{
"settings": {
"analysis": {
"analyzer": {
"value_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"html_strip"
],
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"product_value": {
"type": "text",
"analyzer": "value_analyzer"
},
"locale":{
"type" : "keyword"
}
}
}
}
}
目录字段映射:
PUT catalog
{
"settings": {
"analysis": {
"analyzer": {
"value_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"html_strip"
],
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"catalog_attr_value": {
"type": "text",
"analyzer": "value_analyzer"
},
"locale":{
"type":"keyword"
}
}
}
}
}