【问题标题】:Indexing geospatial in elastic search results in error?在弹性搜索中索引地理空间会导致错误?
【发布时间】:2013-02-24 01:48:54
【问题描述】:
{ title: 'abcccc',
  price: 3300,
  price_per: 'task',
  location: { lat: -33.8756, lon: 151.204 },
  description: 'asdfasdf' 
 }

以上是我要索引的 JSON。但是,当我索引它时,错误是:

{"error":"MapperParsingException[Failed to parse [location]]; nested: ElasticSearchIllegalArgumentException[unknown property [lat]]; ","status":400}

如果我删除“位置”字段,一切正常。

如何索引地理位置?我阅读了教程,但我仍然对它的工作原理感到困惑。它应该像这样工作,对吧......?

【问题讨论】:

  • 请完整说明您采取的导致该错误的步骤。
  • 你试过other formats,例如location: '-33.8756,151.204'?

标签: search lucene elasticsearch


【解决方案1】:

您收到此错误消息是因为字段位置未正确映射。有可能在某个时间点,您尝试在该字段中索引一个字符串,现在它被映射为一个字符串。 Elasticsearch 无法自动检测字段是否包含 geo_point。它必须在映射中明确指定。否则,Elasticsearch 会根据您在第一个索引记录中使用的 geo_point 表示类型将此类字段映射为字符串、数字或对象。一旦将字段添加到映射中,就不能再更改其类型。因此,为了解决这种情况,您需要删除此类型的映射并重新创建它。下面是为 geo_point 字段指定映射的示例:

curl -XDELETE "localhost:9200/geo-test/"
echo
# Set proper mapping. Elasticsearch cannot automatically detect that something is a geo_point:
curl -XPUT "localhost:9200/geo-test" -d '{
    "settings": {
        "index": {
            "number_of_replicas" : 0,
            "number_of_shards": 1
        }
    },
    "mappings": {
        "doc": {
            "properties": {
                "location" : {
                    "type" : "geo_point"
                }
            }
        }
    }
}'
echo
# Put some test data in Sydney
curl -XPUT "localhost:9200/geo-test/doc/1" -d '{ 
    "title": "abcccc",
    "price": 3300,
    "price_per": "task",
    "location": { "lat": -33.8756, "lon": 151.204 },
    "description": "asdfasdf"
 }'
curl -XPOST "localhost:9200/geo-test/_refresh"
echo
# Search, and calculate distance to Brisbane 
curl -XPOST "localhost:9200/geo-test/doc/_search?pretty=true" -d '{
    "query": {
        "match_all": {}
    },
    "script_fields": {
        "distance": {
            "script": "doc['\''location'\''].arcDistanceInKm(-27.470,153.021)"
        }
    },
    "fields": ["title", "location"]
}
'
echo

【讨论】:

    【解决方案2】:

    由于您没有指定如何解析它,因此:

    Parsing through JSON in JSON.NET with unknown property names

    可能会带来一些光线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多