Elasticsearch curl从查询中获取所有需要TourCityId和destinationCountryId的旅行ID

时间:2018-08-09 08:03:52

标签: elasticsearch

我有一些数据

"_source": {
                    "id": "00000000-0000-0188-0000-000000023d07",
                    "departureDestination": {
                        "departureCityId": 392,
                        "destinationCountryId": 146695
                    },
                    "tours": [
                        {
                            "id": 146696,
                            "name": "Рига",
                            "fromCityId": 392
                        },
                        {
                            "id": 521347,
                            "name": "Экскурсионные туры - Рига",
                            "fromCityId": 392
                        },
 ],
                    "hotels": [
                        {
                            "id": 312821,
                            "name": "ALBERT HOTEL 4 *",
                            "tourId": 146696
                        },
                        {
                            "id": 310637,
                            "name": "AMBER SEA HOTEL & SPA 4 *",
                            "tourId": 519120
                        },
                        {
                            "id": 310902,
                            "name": "AMBER SPA BOUTIQUE HOTEL 4 *",
                            "tourId": 519120
                        }

_source": {
                    "id": "00000000-0000-0188-0000-0000000259a4",
                    "departureDestination": {
                        "departureCityId": 392,
                        "destinationCountryId": 154020
                    },
                    "tours": [
                        {
                            "id": 585494,
                            "name": "Адриатика - Апулия",
                            "fromCityId": 392
                        },
                        {
                            "id": 517867,
                            "name": "Адриатика - Каттолика",
                            "fromCityId": 392
                        }
"hotels": [
                        {
                            "id": 9011932,
                            "name": "ABAMAR (RIMINI) 3 *",
                            "tourId": 9013222
                        },
                        {
                            "id": 240190,
                            "name": "ABANO GRAND HOTEL (ABANO TERME) 5* Deluxe",
                            "tourId": 383920
                        }

我想编写一个请求,该请求返回与“ departureCityId”匹配的字段的旅行ID 我写了一个查询,但没有返回匹配,如何使它只返回ID

such curl -X GET "localhost:9200/countries_reference_book/_search" -H 'Content-Type: application/json' -d'{"query": {"dis_max": {"queries": [{ "match": { "departureCityId":392}},{ "match"{"destinationCountryId":146695}}],"tie_breaker": 0.3}}}'

我希望用户输入两个参数DerivationCityId和destinationCountryId,并且它应该仅返回游览ID。从上面的json中,如果用户分别输入392和146695,则应返回

"tours": [
                        {
                            "id": 146696,
                            "name": "Рига",
                            "fromCityId": 392
                        },
                        {
                            "id": 521347,
                            "name": "Экскурсионные туры - Рига",
                            "fromCityId": 392
                        },

我的索引

{
    "countries_reference_book": {
        "aliases": {},
        "mappings": {
            "countriesreferencebook": {
                "properties": {
                    "departureDestination": {
                        "properties": {
                            "departureCityId": {
                                "type": "long"
                            },
                            "destinationCountryId": {
                                "type": "long"
                            }
                        }
                    },
                    "hotels": {
                        "properties": {
                            "id": {
                                "type": "long"
                            },
                            "name": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "tourId": {
                                "type": "long"
                            }
                        }
                    },
                    "id": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "regions": {
                        "properties": {
                            "id": {
                                "type": "long"
                            },
                            "name": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            }
                        }
                    },
                    "tours": {
                        "properties": {
                            "fromCityId": {
                                "type": "long"
                            },
                            "id": {
                                "type": "long"
                            },
                            "name": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "settings": {

0 个答案:

没有答案