Cartesian-bounds aggregation

すべての値を含む空間境界ボックスを計算するメトリック集約で、PointまたはShapeフィールドに対して行われます。

例:

Python

  1. resp = client.indices.create(
  2. index="museums",
  3. mappings={
  4. "properties": {
  5. "location": {
  6. "type": "point"
  7. }
  8. }
  9. },
  10. )
  11. print(resp)
  12. resp1 = client.bulk(
  13. index="museums",
  14. refresh=True,
  15. operations=[
  16. {
  17. "index": {
  18. "_id": 1
  19. }
  20. },
  21. {
  22. "location": "POINT (491.2350 5237.4081)",
  23. "city": "Amsterdam",
  24. "name": "NEMO Science Museum"
  25. },
  26. {
  27. "index": {
  28. "_id": 2
  29. }
  30. },
  31. {
  32. "location": "POINT (490.1618 5236.9219)",
  33. "city": "Amsterdam",
  34. "name": "Museum Het Rembrandthuis"
  35. },
  36. {
  37. "index": {
  38. "_id": 3
  39. }
  40. },
  41. {
  42. "location": "POINT (491.4722 5237.1667)",
  43. "city": "Amsterdam",
  44. "name": "Nederlands Scheepvaartmuseum"
  45. },
  46. {
  47. "index": {
  48. "_id": 4
  49. }
  50. },
  51. {
  52. "location": "POINT (440.5200 5122.2900)",
  53. "city": "Antwerp",
  54. "name": "Letterenhuis"
  55. },
  56. {
  57. "index": {
  58. "_id": 5
  59. }
  60. },
  61. {
  62. "location": "POINT (233.6389 4886.1111)",
  63. "city": "Paris",
  64. "name": "Musée du Louvre"
  65. },
  66. {
  67. "index": {
  68. "_id": 6
  69. }
  70. },
  71. {
  72. "location": "POINT (232.7000 4886.0000)",
  73. "city": "Paris",
  74. "name": "Musée d'Orsay"
  75. }
  76. ],
  77. )
  78. print(resp1)
  79. resp2 = client.search(
  80. index="museums",
  81. size="0",
  82. query={
  83. "match": {
  84. "name": "musée"
  85. }
  86. },
  87. aggs={
  88. "viewport": {
  89. "cartesian_bounds": {
  90. "field": "location"
  91. }
  92. }
  93. },
  94. )
  95. print(resp2)

Ruby

  1. response = client.indices.create(
  2. index: 'museums',
  3. body: {
  4. mappings: {
  5. properties: {
  6. location: {
  7. type: 'point'
  8. }
  9. }
  10. }
  11. }
  12. )
  13. puts response
  14. response = client.bulk(
  15. index: 'museums',
  16. refresh: true,
  17. body: [
  18. {
  19. index: {
  20. _id: 1
  21. }
  22. },
  23. {
  24. location: 'POINT (491.2350 5237.4081)',
  25. city: 'Amsterdam',
  26. name: 'NEMO Science Museum'
  27. },
  28. {
  29. index: {
  30. _id: 2
  31. }
  32. },
  33. {
  34. location: 'POINT (490.1618 5236.9219)',
  35. city: 'Amsterdam',
  36. name: 'Museum Het Rembrandthuis'
  37. },
  38. {
  39. index: {
  40. _id: 3
  41. }
  42. },
  43. {
  44. location: 'POINT (491.4722 5237.1667)',
  45. city: 'Amsterdam',
  46. name: 'Nederlands Scheepvaartmuseum'
  47. },
  48. {
  49. index: {
  50. _id: 4
  51. }
  52. },
  53. {
  54. location: 'POINT (440.5200 5122.2900)',
  55. city: 'Antwerp',
  56. name: 'Letterenhuis'
  57. },
  58. {
  59. index: {
  60. _id: 5
  61. }
  62. },
  63. {
  64. location: 'POINT (233.6389 4886.1111)',
  65. city: 'Paris',
  66. name: 'Musée du Louvre'
  67. },
  68. {
  69. index: {
  70. _id: 6
  71. }
  72. },
  73. {
  74. location: 'POINT (232.7000 4886.0000)',
  75. city: 'Paris',
  76. name: "Musée d'Orsay"
  77. }
  78. ]
  79. )
  80. puts response
  81. response = client.search(
  82. index: 'museums',
  83. size: 0,
  84. body: {
  85. query: {
  86. match: {
  87. name: 'musée'
  88. }
  89. },
  90. aggregations: {
  91. viewport: {
  92. cartesian_bounds: {
  93. field: 'location'
  94. }
  95. }
  96. }
  97. }
  98. )
  99. puts response

Js

  1. const response = await client.indices.create({
  2. index: "museums",
  3. mappings: {
  4. properties: {
  5. location: {
  6. type: "point",
  7. },
  8. },
  9. },
  10. });
  11. console.log(response);
  12. const response1 = await client.bulk({
  13. index: "museums",
  14. refresh: "true",
  15. operations: [
  16. {
  17. index: {
  18. _id: 1,
  19. },
  20. },
  21. {
  22. location: "POINT (491.2350 5237.4081)",
  23. city: "Amsterdam",
  24. name: "NEMO Science Museum",
  25. },
  26. {
  27. index: {
  28. _id: 2,
  29. },
  30. },
  31. {
  32. location: "POINT (490.1618 5236.9219)",
  33. city: "Amsterdam",
  34. name: "Museum Het Rembrandthuis",
  35. },
  36. {
  37. index: {
  38. _id: 3,
  39. },
  40. },
  41. {
  42. location: "POINT (491.4722 5237.1667)",
  43. city: "Amsterdam",
  44. name: "Nederlands Scheepvaartmuseum",
  45. },
  46. {
  47. index: {
  48. _id: 4,
  49. },
  50. },
  51. {
  52. location: "POINT (440.5200 5122.2900)",
  53. city: "Antwerp",
  54. name: "Letterenhuis",
  55. },
  56. {
  57. index: {
  58. _id: 5,
  59. },
  60. },
  61. {
  62. location: "POINT (233.6389 4886.1111)",
  63. city: "Paris",
  64. name: "Musée du Louvre",
  65. },
  66. {
  67. index: {
  68. _id: 6,
  69. },
  70. },
  71. {
  72. location: "POINT (232.7000 4886.0000)",
  73. city: "Paris",
  74. name: "Musée d'Orsay",
  75. },
  76. ],
  77. });
  78. console.log(response1);
  79. const response2 = await client.search({
  80. index: "museums",
  81. size: 0,
  82. query: {
  83. match: {
  84. name: "musée",
  85. },
  86. },
  87. aggs: {
  88. viewport: {
  89. cartesian_bounds: {
  90. field: "location",
  91. },
  92. },
  93. },
  94. });
  95. console.log(response2);

Console

  1. PUT /museums
  2. {
  3. "mappings": {
  4. "properties": {
  5. "location": {
  6. "type": "point"
  7. }
  8. }
  9. }
  10. }
  11. POST /museums/_bulk?refresh
  12. {"index":{"_id":1}}
  13. {"location": "POINT (491.2350 5237.4081)", "city": "Amsterdam", "name": "NEMO Science Museum"}
  14. {"index":{"_id":2}}
  15. {"location": "POINT (490.1618 5236.9219)", "city": "Amsterdam", "name": "Museum Het Rembrandthuis"}
  16. {"index":{"_id":3}}
  17. {"location": "POINT (491.4722 5237.1667)", "city": "Amsterdam", "name": "Nederlands Scheepvaartmuseum"}
  18. {"index":{"_id":4}}
  19. {"location": "POINT (440.5200 5122.2900)", "city": "Antwerp", "name": "Letterenhuis"}
  20. {"index":{"_id":5}}
  21. {"location": "POINT (233.6389 4886.1111)", "city": "Paris", "name": "Musée du Louvre"}
  22. {"index":{"_id":6}}
  23. {"location": "POINT (232.7000 4886.0000)", "city": "Paris", "name": "Musée d'Orsay"}
  24. POST /museums/_search?size=0
  25. {
  26. "query": {
  27. "match": { "name": "musée" }
  28. },
  29. "aggs": {
  30. "viewport": {
  31. "cartesian_bounds": {
  32. "field": "location"
  33. }
  34. }
  35. }
  36. }
cartesian_bounds集約は、境界を取得するために使用するフィールドを指定します。これはPointまたはShapeタイプでなければなりません。

geo_bounds集約の場合とは異なり、wrap_longitudeを設定するオプションはありません。これは、デカルト空間がユークリッドであり、自身に戻ることがないためです。したがって、境界は常に最小x値が最大x値以下になります。

上記の集約は、名前が「musée」と一致するすべてのドキュメントの位置フィールドの境界ボックスを計算する方法を示しています。

上記の集約に対する応答:

Console-Result

  1. {
  2. ...
  3. "aggregations": {
  4. "viewport": {
  5. "bounds": {
  6. "top_left": {
  7. "x": 232.6999969482422,
  8. "y": 4886.111328125
  9. },
  10. "bottom_right": {
  11. "x": 233.63890075683594,
  12. "y": 4886.0
  13. }
  14. }
  15. }
  16. }
  17. }

Cartesian Bounds Aggregation on shape fields

デカルト境界集約は、cartesian_shapeフィールドでもサポートされています。

例:

Python

  1. resp = client.indices.create(
  2. index="places",
  3. mappings={
  4. "properties": {
  5. "geometry": {
  6. "type": "shape"
  7. }
  8. }
  9. },
  10. )
  11. print(resp)
  12. resp1 = client.bulk(
  13. index="places",
  14. refresh=True,
  15. operations=[
  16. {
  17. "index": {
  18. "_id": 1
  19. }
  20. },
  21. {
  22. "name": "NEMO Science Museum",
  23. "geometry": "POINT(491.2350 5237.4081)"
  24. },
  25. {
  26. "index": {
  27. "_id": 2
  28. }
  29. },
  30. {
  31. "name": "Sportpark De Weeren",
  32. "geometry": {
  33. "type": "Polygon",
  34. "coordinates": [
  35. [
  36. [
  37. 496.5305328369141,
  38. 5239.347642069457
  39. ],
  40. [
  41. 496.6979026794433,
  42. 5239.172175893484
  43. ],
  44. [
  45. 496.9425201416015,
  46. 5239.238958618537
  47. ],
  48. [
  49. 496.7944622039794,
  50. 5239.420969150824
  51. ],
  52. [
  53. 496.5305328369141,
  54. 5239.347642069457
  55. ]
  56. ]
  57. ]
  58. }
  59. }
  60. ],
  61. )
  62. print(resp1)
  63. resp2 = client.search(
  64. index="places",
  65. size="0",
  66. aggs={
  67. "viewport": {
  68. "cartesian_bounds": {
  69. "field": "geometry"
  70. }
  71. }
  72. },
  73. )
  74. print(resp2)

Ruby

  1. response = client.indices.create(
  2. index: 'places',
  3. body: {
  4. mappings: {
  5. properties: {
  6. geometry: {
  7. type: 'shape'
  8. }
  9. }
  10. }
  11. }
  12. )
  13. puts response
  14. response = client.bulk(
  15. index: 'places',
  16. refresh: true,
  17. body: [
  18. {
  19. index: {
  20. _id: 1
  21. }
  22. },
  23. {
  24. name: 'NEMO Science Museum',
  25. geometry: 'POINT(491.2350 5237.4081)'
  26. },
  27. {
  28. index: {
  29. _id: 2
  30. }
  31. },
  32. {
  33. name: 'Sportpark De Weeren',
  34. geometry: {
  35. type: 'Polygon',
  36. coordinates: [
  37. [
  38. [
  39. 496.5305328369141,
  40. 5239.347642069457
  41. ],
  42. [
  43. 496.6979026794433,
  44. 5239.172175893484
  45. ],
  46. [
  47. 496.9425201416015,
  48. 5239.238958618537
  49. ],
  50. [
  51. 496.7944622039794,
  52. 5239.420969150824
  53. ],
  54. [
  55. 496.5305328369141,
  56. 5239.347642069457
  57. ]
  58. ]
  59. ]
  60. }
  61. }
  62. ]
  63. )
  64. puts response
  65. response = client.search(
  66. index: 'places',
  67. size: 0,
  68. body: {
  69. aggregations: {
  70. viewport: {
  71. cartesian_bounds: {
  72. field: 'geometry'
  73. }
  74. }
  75. }
  76. }
  77. )
  78. puts response

Js

  1. const response = await client.indices.create({
  2. index: "places",
  3. mappings: {
  4. properties: {
  5. geometry: {
  6. type: "shape",
  7. },
  8. },
  9. },
  10. });
  11. console.log(response);
  12. const response1 = await client.bulk({
  13. index: "places",
  14. refresh: "true",
  15. operations: [
  16. {
  17. index: {
  18. _id: 1,
  19. },
  20. },
  21. {
  22. name: "NEMO Science Museum",
  23. geometry: "POINT(491.2350 5237.4081)",
  24. },
  25. {
  26. index: {
  27. _id: 2,
  28. },
  29. },
  30. {
  31. name: "Sportpark De Weeren",
  32. geometry: {
  33. type: "Polygon",
  34. coordinates: [
  35. [
  36. [496.5305328369141, 5239.347642069457],
  37. [496.6979026794433, 5239.172175893484],
  38. [496.9425201416015, 5239.238958618537],
  39. [496.7944622039794, 5239.420969150824],
  40. [496.5305328369141, 5239.347642069457],
  41. ],
  42. ],
  43. },
  44. },
  45. ],
  46. });
  47. console.log(response1);
  48. const response2 = await client.search({
  49. index: "places",
  50. size: 0,
  51. aggs: {
  52. viewport: {
  53. cartesian_bounds: {
  54. field: "geometry",
  55. },
  56. },
  57. },
  58. });
  59. console.log(response2);

Console

  1. PUT /places
  2. {
  3. "mappings": {
  4. "properties": {
  5. "geometry": {
  6. "type": "shape"
  7. }
  8. }
  9. }
  10. }
  11. POST /places/_bulk?refresh
  12. {"index":{"_id":1}}
  13. {"name": "NEMO Science Museum", "geometry": "POINT(491.2350 5237.4081)" }
  14. {"index":{"_id":2}}
  15. {"name": "Sportpark De Weeren", "geometry": { "type": "Polygon", "coordinates": [ [ [ 496.5305328369141, 5239.347642069457 ], [ 496.6979026794433, 5239.1721758934835 ], [ 496.9425201416015, 5239.238958618537 ], [ 496.7944622039794, 5239.420969150824 ], [ 496.5305328369141, 5239.347642069457 ] ] ] } }
  16. POST /places/_search?size=0
  17. {
  18. "aggs": {
  19. "viewport": {
  20. "cartesian_bounds": {
  21. "field": "geometry"
  22. }
  23. }
  24. }
  25. }

Console-Result

  1. {
  2. ...
  3. "aggregations": {
  4. "viewport": {
  5. "bounds": {
  6. "top_left": {
  7. "x": 491.2349853515625,
  8. "y": 5239.4208984375
  9. },
  10. "bottom_right": {
  11. "x": 496.9425048828125,
  12. "y": 5237.408203125
  13. }
  14. }
  15. }
  16. }
  17. }