我在 elasticsearch 中有此查询,该查询可提供预期的正确结果,但是当我尝试使用springboot通过 ElasticsearchCrudRepository 搜索时,它以随机顺序给出不同的结果
我在github上搜索了其他stackoverflow问题,有人说这是版本问题,但是我正在使用相同版本的spring-data-elasticsearch以及我的elasticsearch
ElasticsearchCrudRepository查询:
@Component
public interface MedicineRepository extends ElasticsearchCrudRepository<Medicine, String> {
@Query("{ \"function_score\" :{ \"query\":{ \"bool\": { \"must_not\": [ { \"match\": { \"status\": \"Inactive\" } }, { \"match\": { \"status\": \"Pending\" } } ], \"must\": [ { \"match\": { \"location\": \"?1\" } }, { \"bool\": { \"should\": [ { \"multi_match\": { \"query\": \"?0\", \"type\": \"best_fields\", \"fields\": [ \"name^5\", \"brand_name^3\" ], \"boost\": 1, \"fuzziness\": \"AUTO\", \"prefix_length\": 2 } }, { \"multi_match\": { \"query\": \"?0\", \"type\": \"phrase_prefix\", \"fields\": [ \"name^5\", \"brand_name^3\" ], \"boost\": 3 } }, { \"multi_match\": { \"query\": \"?0\", \"type\": \"phrase_prefix\", \"fields\": [ \"sku\" ], \"boost\": 5 } } ] } } ] } }, \"boost\": \"2\", \"functions\": [ { \"filter\": { \"match\": { \"status\": \"Active\" } }, \"weight\": 2 } ], \"max_boost\": 10, \"score_mode\": \"max\", \"boost_mode\": \"sum\", \"min_score\" : 0 } }")
Page<Medicine> findByLocationAnd_SkuOrNameOrBrand(String query, String location, Pageable pageable);
}
普通ElasticSearch查询:
{
"query" :
{
"function_score" :{
"query":{
"bool": {
"must_not": [
{
"match": {
"status": "Inactive"
}
},
{
"match": {
"status": "Pending"
}
}
],
"must": [
{
"match": {
"location": "Jaipur"
}
},
{
"bool": {
"should": [
{
"multi_match": {
"query": "crozin",
"type": "best_fields",
"fields": [
"name^5",
"brand_name^3"
],
"boost": 1,
"fuzziness": "AUTO",
"prefix_length": 2
}
},
{
"multi_match": {
"query": "crozin",
"type": "phrase_prefix",
"fields": [
"name^5",
"brand_name^3"
],
"boost": 3
}
},
{
"multi_match": {
"query": "crozin",
"type": "phrase_prefix",
"fields": [
"sku"
],
"boost": 5
}
}
]
}
}
]
}
},
"boost": "2",
"functions": [
{
"filter": { "match": { "status": "Active" } },
"weight": 2
}
],
"max_boost": 10,
"score_mode": "max",
"boost_mode": "sum",
"min_score" : 0
}
}
}