我正尝试使用matchQuery
和fuzzyQuery
从弹性搜索中获取文档,但是两个API的响应计数都相同。
例如:
方案1(带有matchQuery)
Am使用matchQuery搜索阀门,并使用下面的36
API获取matchQuery
的计数
QueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("catalog_value", "valve"))
.filter(QueryBuilders.termQuery("locale", "en_US" ));
如果我搜索valves
,也只会得到14
个计数。
方案2(带有FuzzyQuery)
Am使用FuzzyQuery搜索阀门,并使用下面的34
API获取fuzzyQuery
的计数
QueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.fuzzyQuery("catalog_value", "valve"))
.filter(QueryBuilders.termQuery("locale", "en_US"));
如果我搜索valves
,也只会得到14
个计数。实际上,如果我们使用FuzzyQuery,期望valve
和valves
的计数应该相同。
任何人都对FuzzyQuery API有所了解。
我使用的是ElasticSearch 6.2.3版本。
匹配valves
的示例文档。
{
"_index":"catalog",
"_type":"doc",
"_id":"517yxmQB1-MO2Tblt7C3",
"_score":1.0,
"_source":{
"catalog_name":"family451",
"catalog_value":"These control valves range with actuation choices featuring.",
"catalog_id":41065,
"@version":"1",
"locale":"en_US",
"@timestamp":"2018-07-23T11:42:29.751Z"
}
请找到我的地图详细信息:
PUT catalog
{
"settings": {
"analysis": {
"analyzer": {
"value_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"html_strip"
],
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"catalog_value": {
"type": "text",
"analyzer": "value_analyzer"
},
"catalog_id": {
"type": "long"
},
"catalog_name":{
"type":"keyword"
},
"locale":{
"type":"keyword"
}
}
}
}
}
更新
我已经在以下情况下进行了测试,并且得到了以下计数。
valve --> 17
valves --> 7
valvess --> 7
valvesss --> 8
val --> 17
valv --> 17
更新2
使用以下经过修改的查询并获得以下结果计数。
QueryBuilder qb1 = QueryBuilders.boolQuery()
.must(QueryBuilders.fuzzyQuery("catalog_attr_value", "valve").boost(1.0f).prefixLength(0).fuzziness(Fuzziness.ONE).transpositions(true))
.filter(QueryBuilders.termQuery("locale", "en_US"));
valve --> 17
valves --> 7
valvess --> 8
valvesss --> 0
val --> 17
valv --> 17
更新3
使用下面的FuzzyQuery不能得到valve
和Valves
的正确结果计数。
QueryBuilder qb1 = QueryBuilders.boolQuery()
.must(QueryBuilders.fuzzyQuery("product_attr_value", keyword).boost(1.0f).prefixLength(0).fuzziness(Fuzziness.AUTO).transpositions(true));
对于valve
和valves
搜索,我总共得到10个结果计数(将计数限制为10),并且没有文档匹配在一起。
例如,以下是我在valve
和valves
搜索中获得的ID
阀门:
17194
219575
219574
280638
282288
298177
295626
4112
219069
219381
valve
搜索的示例响应
"hits":[
{
"_index":"product_offering",
"_type":"doc",
"_id":"kE89_2QBfp1CuLwJxs-W",
"_score":3.0630755,
"_source":{
"product_status":"ACT",
"@timestamp":"2018-08-03T10:03:12.194Z",
"product_code":"M9000-560",
"std_delivery_time":0,
"product_attr_type":null,
"label":"long_description",
"product_attr_value":"Ball Valve Linkage Kit for applying M9203 and M9208 Series Actuators to VG1000 Series Valves",
"is_product_visible":1,
"product_name":"product17167",
"product_group":"single",
"product_id":17194,
"@version":"1",
"catalog_id":264,
"locale":"en_US",
"expiration_date":null,
"product_type":"accessory",
"min_order_quantity":1,
"product_attr_name":"product17167_long_description"
}
},
阀门:
15680
15572
15599
15615
15674
15650
15526
15543
6869
6868
用于valves
搜索的示例响应(搜索valve
时不可用)
"hits":[
{
"_index":"product_offering",
"_type":"doc",
"_id":"A089_2QBfp1CuLwJ-d9C",
"_score":3.8922772,
"_source":{
"product_status":"DSC",
"@timestamp":"2018-08-03T10:03:26.343Z",
"product_code":"M9116-GDC-1N2",
"std_delivery_time":0,
"product_attr_type":null,
"label":"long_description",
"product_attr_value":"These electric actuators have been specially designed for the motorised operation of various types of water valves and fittings such as mixing valves, butterfly valves and ball valves.",
"is_product_visible":0,
"product_name":"product4459",
"product_group":"single",
"product_id":15680,
"@version":"1",
"catalog_id":319,
"locale":"en_US",
"expiration_date":null,
"product_type":"legacy",
"min_order_quantity":1,
"product_attr_name":"product4459_long_description"
}
},