如何根据结果命中来自Elasticsearch中某个字段的条件进行过滤?

时间:2018-06-11 10:42:05

标签: elasticsearch

我有一个弹性搜索 bool 查询,其中多个应该子句将多个匹配查询与多个字段组合在一起提升价值。

说我有5个字段:

productName / currency / country / identifierNumber

我想用这个逻辑有条件地过滤我的结果:

  • 如果 bool查询的结果(点击)来自该字段的匹配查询( productName 货币过滤。

  • 如果 bool查询的结果(点击)来自该字段的匹配查询( identifierNumber 不要按货币

    过滤

    更新



{
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "multi_match": {
                                "query": "parameter",
                                "fields": [
                                    "productName.test^8",
                                    "productName.raw^4",
                                    "_all^2",
                                    "Zone^10",
                                    "category^12",
                                    "class^71"
                                ],
                                "fuzziness": "1",
                                "prefix_length": 1
                            }
                        },
                        {
                            "match": {
                                "productName.test": {
                                    "query": "parameter",
                                    "operator": "and",
                                    "fuzziness": "1",
                                    "prefix_length": 3,
                                    "boost": 1000
                                }
                            }
                        },
                        {
                            "match": {
                                "productName.raw": {
                                    "query": "parameter",
                                    "operator": "or",
                                    "fuzziness": "AUTO",
                                    "prefix_length": 3,
                                    "boost": 10
                                }
                            }
                        },
                        {
                            "match": {
                                "identifierNumber": {
                                    "query": "parameter",
                                    "boost": 3000
                                }
                            }
                        },
                        {
                            "term": {
                                "tic": {
                                    "value": "parameter",
                                    "boost": 30000
                                }
                            }
                        },
                        {
                            "match": {
                                "_all": {
                                    "query": "parameter",
                                    "operator": "or",
                                    "fuzziness": "1",
                                    "prefix_length": 2,
                                    "boost": 10
                                }
                            }
                        }
                    ]
                }
            },
            "functions": [
                {
                    "field_value_factor": {
                        "field": "productvalue"
                    }
                }
            ],
            "boost_mode": "multiply"
        }
    },
    "size": 30,
    "highlight": {
        "fields": {
            "*": {}
        },
        "require_field_match": false
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "match": {
                        "countryName": "France"
                    }
                }]
        }
    }
}




0 个答案:

没有答案