ElasticSearch结合条件语句'和'与'或'

时间:2016-11-14 11:25:08

标签: json elasticsearch nest

以下查询的目的是为每个条件返回n个结果,即它必须与合作伙伴16匹配并匹配'venueTown'或合作伙伴16并匹配'venueName'。目前,它返回每个字段必须包含相同字符串的结果。在我的案例字段中:name,venueName和venueTown必须包含manchester,但我想要每对{(partnersites,venueName),(partnersites,venueTown)}的单独结果。

    {
    "size": 0,
    "_source": ["groupedName", "groupedDisplayName", "groupedUrl", "eventCode", "venueName", "venueTown", "venueId", "media"],
    "query": {
        "bool": {
            "must": [{
                "match": {
                    "partnersites": {
                        "query": "16"
                    }
                }
            }, {
                "match": {
                    "name": "manchester"
                }
            }, {
                "match": {
                    "venueName": "manchester"
                }
            }, {
                "match": {
                    "venueTown": "manchester"
                }
            }, {
                "match": {
                    "venueTown": "manchester"
                }
            }]
        }
    },
    "aggs": {
        "distinct_names": {
            "terms": {
                "field": "name.keyword",
                "size": 10
            },
            "aggs": {
                "top_tag_hits": {
                    "top_hits": {
                        "size": 1,
                        "_source": ["groupedName", "groupedDisplayName", "groupedUrl", "eventCode", "venueName", "venueTown", "venueId", "media"]
                    }
                }
            }
        },
        "distinct_venues": {
            "terms": {
                "field": "venueName.keyword",
                "size": 10
            },
            "aggs": {
                "top_tag_hits": {
                    "top_hits": {
                        "size": 1,
                        "_source": ["groupedName", "groupedDisplayName", "groupedUrl", "eventCode", "venueName", "venueTown", "venueId", "media"]
                    }
                }
            }
        },

        "distinct_towns": {
            "terms": {
                "field": "venueTown.keyword",
                "size": 10
            },
            "aggs": {
                "top_tag_hits": {
                    "top_hits": {
                        "size": 1,
                        "_source": ["groupedName", "groupedDisplayName", "groupedUrl", "eventCode", "venueName", "venueTown", "venueId", "media"]
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

试试这个:

private_ip={{item}}