Elasticsearch: поиск Geo_spacial в списке вложенных объектов - PullRequest
0 голосов
/ 21 апреля 2019

Я использую Elasticsearch 6.3 и spring-data -asticsearch, у меня есть индекс restaurant с отображением ниже:

{
  "mapping": {
    "restaurant": {
      "properties": {
        "id": {
          "type": "keyword"
        },
        "name": {
          "type": "text",
          "store": true,
          "analyzer": "custom_analyzer",
          "search_analyzer": "custom_search_analyzer"
        },
        "locations": {
          "type": "nested",
          "include_in_parent": true,
          "properties": {
            "id": {
              "type": "long"
            },
            "fullAddress": {
              "type": "text"
            },
            "geo": {
              "type": "geo_point"
            },
            "phone": {
              "type": "keyword"
            }
          }
        },
        "menus": {
          "type": "nested",
          "properties": {
            "id": {
              "type": "long"
            },
            "name": {
              "type": "text",
              "store": true,
              "analyzer": "custom_analyzer",
              "search_analyzer": "custom_search_analyzer"
            }
          }
        }
      }
    }
  }
}

Это пример документа этого сопоставления:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "restaurants",
        "_type": "restaurants",
        "_id": "1",
        "_score": 1,
        "_source": {
          "id": 1,
          "name": "Mc Donald",
          "menus": [
            {
              "id": 7097,
              "name": "Big Fish"
            },
            {
              "id": 13899,
              "name": "Big Mac"
            }
          ],
          "locations": [
            {
              "id": 1,
              "fullAddress": "7 Bd Solférino, 59000 Lille",
              "geo": { "lat": 50.6423461,"lon": 3.1390441},
              "phone": "0305060804"
            },
            {
              "id": 2,
              "fullAddress": "7 Rue Nationale, 75000 Paris",
              "geo": { "lat": 40.6423461,"lon": -7.1390441},
              "phone": "0305060804"
            }
          ]
        }
      }
    ]
  }
}

Я пытаюсь найти все рестораны вокруг себя, например, я ищу ближайший Мак Дональд.

Я пробовал 2 запроса ниже, но они возвращают список пустых сообщений:

Запрос 1: (Использование пост-фильтрации)

GET restaurants/_search
{
  "query": {
    "match": {
      "name": "donald"
    }
  },
  "post_filter": {
    "nested": {
      "path": "locations",
      "query": {
        "geo_distance": {
          "distance": "10km",
          "locations.geo": [50.6423461, 3.1390441]
        }
      }
    }
  }
}

Запрос 2: (Использование фильтрации внутри запроса)

GET restaurants/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "donald"
          }
        }
      ],
      "filter": {
        "nested": {
          "path": "locations",
          "query": {
            "geo_distance": {
              "distance": "10km",
              "locations.geo": [50.6423461,3.1390441]
            }
          },
          "inner_hits": {}
        }
      }
    }
  }
}

ПОЖАЛУЙСТА, может кто-нибудь сказать мне, что я делаю неправильно в моем отображении или запросах. Спасибо заранее.

...