在elasticsearch中未生成geohash

ykejflvf  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(423)

我创建了一个索引,如下所示:

  1. POST /cabtrails
  2. {
  3. "settings" :
  4. {
  5. "number_of_shards" : 3,
  6. "number_of_replicas" : 1
  7. },
  8. "mappings" : {
  9. "cabtrail" :{
  10. "properties" : {
  11. "location": {
  12. "type": "geo_point",
  13. "geohash_prefix": true,
  14. "geohash_precision": "5m"
  15. },
  16. "capture_time": {
  17. "type" : "long"
  18. },
  19. "client_id": {
  20. "type" : "long"
  21. }
  22. }
  23. }
  24. }
  25. }

它工作正常,并创建了一个索引。
我输入了一个示例文档:

  1. POST cabtrails/cabtrail
  2. {
  3. "capture_time": 1431849367077,
  4. "client_id": 865527029812357,
  5. "location": "13.0009316,77.5947316"
  6. }

这也行。在这里,我希望elasticsearch将生成一个geohash字段/条目,我可以使用它。
但是,当我询问时,我得到:

  1. GET cabtrails/_search
  2. {
  3. "took": 2,
  4. "timed_out": false,
  5. "_shards": {
  6. "total": 3,
  7. "successful": 3,
  8. "failed": 0
  9. },
  10. "hits": {
  11. "total": 1,
  12. "max_score": 1,
  13. "hits": [
  14. {
  15. "_index": "cabtrails",
  16. "_type": "cabtrail",
  17. "_id": "AU2LrEaze2aqxPjHm-UI",
  18. "_score": 1,
  19. "_source": {
  20. "capture_time": 1431849367077,
  21. "client_id": 865527029812357,
  22. "location": "13.0009316,77.5947316"
  23. }
  24. }
  25. ]
  26. }
  27. }

我期待一个像这样的地理哈希字符串 u10hbp 在查询结果的某处,我可以使用它来查询未来的位置点。或者我对geohash+es的概念搞砸了??救命!!

ni65a41a

ni65a41a1#

根据启用geohash标志的文档,geo\u point索引geohash值。
索引的内容和响应的\u源字段表示的内容有所不同。
响应中的源字段是传递给elasticsearch进行索引的原始json文档。
启用geohash标志时,geo_点类型将使用geohash表示法编制索引,但实际的源文档不会更改
要了解geohash标志如何补充geo\u point type的索引方式,您可以使用fielddata\u fields api:
对于上面的示例,它将在以下几行中显示:

  1. **Query**
  2. POST cabtrails/_search
  3. {
  4. "fielddata_fields" :["location","location.geohash"]
  5. }

答复:

  1. "hits": {
  2. "total": 1,
  3. "max_score": 1,
  4. "hits": [
  5. {
  6. "_index": "cabtrails",
  7. "_type": "cabtrail",
  8. "_id": "AU2NRn_OsXnJTKeurUsn",
  9. "_score": 1,
  10. "_source": {
  11. "capture_time": 1431849367077,
  12. "client_id": 865527029812357,
  13. "location": "13.0009316,77.5947316"
  14. },
  15. "fields": {
  16. "location": [
  17. {
  18. "lat": 13.0009316,
  19. "lon": 77.5947316
  20. }
  21. ],
  22. "location.geohash": [
  23. "t",
  24. "td",
  25. "tdr",
  26. "tdr1",
  27. "tdr1v",
  28. "tdr1vw",
  29. "tdr1vww",
  30. "tdr1vwwz",
  31. "tdr1vwwzb",
  32. "tdr1vwwzbm"
  33. ]
  34. }
  35. }
  36. ]
  37. }
展开查看全部

相关问题