0

我使用以下方法创建索引:

curl -XPUT localhost:9200/mobapp -d '{
  "mappings": {
    "publish_messages": {
      "properties": {
        "title": {
          "type": "string"
        },
        "location": {
          "type": "nested",
          "position": {
            "type": "geo_point"
          },
          "name": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "city": {
            "type": "integer"
          }
        },
        "time": {
          "type": "date",
          "format": "dd-MM-YYYY"
        }
      }
    }
  }
}'

我有这个索引

  "hits": [
    {
      "_index": "mobapp",
      "_type": "publish_messages",
      "_id": "184123e0-6123-11e5-83d5-7bdc2a9aa3c7",
      "_score": 1,
      "_source": {
        "title": "Kolkata rocka",
        "tags": [
          "Tag5",
          "Tag4"
        ],
        "date": "2015-09-22T12:11:46.335Z",
        "location": {
          "position": {
            "lat": 11.81776,
            "lon": 10.9376
          },
          "country": "India",
          "locality": "Bengaluru",
          "sublocality_level_1": "Koramangala"
        }
      }
    }
  ]

我正在尝试执行此查询:

    FilterBuilder filter = geoDistanceFilter("location")   
        .point(lat, lon)
        .distance(distanceRangeInkm, DistanceUnit.KILOMETERS)
        .optimizeBbox("memory")                                     
        .geoDistance(GeoDistance.ARC);        

    FilterBuilder boolFilter = boolFilter()
        .must(termFilter("tags", tag))
        .must(filter);

    GeoDistanceSortBuilder geoSort = SortBuilders.geoDistanceSort("location").point(lat, lon).order(SortOrder.ASC);

    SearchResponse searchResponse 
            = client.prepareSearch(AppConstants.ES_INDEX)
               .setTypes("publish_messages")
               .addSort("time", SortOrder.DESC)
               .addSort(geoSort)
               .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
               .setPostFilter(boolFilter)
               .setFrom(startPage).setSize(AppConstants.DEFAULT_PAGINATION_SIZE)
               .execute()
               .actionGet();    

我正进入(状态QueryParsingException[[mobapp] failed to find geo_point field [location.position]]; }

4

1 回答 1

0

如果你只想将你的位置数据保存在一起,你不需要使用nested类型,只需使用普通object类型(即默认),像这样:

curl -XPUT localhost:9200/mobapp -d '{
  "mappings": {
    "publish_messages": {
      "properties": {
        "title": {
          "type": "string"
        },
        "location": {
          "type": "object",        <--- use object here
          "properties": {          <--- and don't forget properties here
            "position": {
              "type": "geo_point"
            },
            "name": {
              "type": "string"
            },
            "state": {
              "type": "string"
            },
            "country": {
              "type": "string"
            },
            "city": {
              "type": "integer"
            }
          }
        },
        "time": {
          "type": "date",
          "format": "dd-MM-YYYY"
        }
      }
    }
  }
}'

请注意,您首先需要清除当前索引curl -XDELETE localhost:9200/mobapp,然后使用上述命令重新创建它并重新索引您的数据。您的查询应该在之后工作。

于 2015-09-25T04:15:16.227 回答