title: Elasticsearch Shape query to find the bounding polygon and background color from Nested JSON (Google OCR response)
body: <p>I have a response from an OCR application which is a JSON similar to Google Vision OCR response. I want to put this in Elasticsearch in order to perform a shape query. Although I am able to put the JSON in Elasticsearch, I am not able to come up with a perfect <code>schema</code> and <code>mapping</code> to perform a search on the basis of the shape or the <code>boundingPoly</code> and the <code>bgColor</code>.</p>
  
  <p>I am pretty new to <strong>Elasticsearch</strong> and I have few questions.</p>
  
  <p><strong>(1)</strong> How can I perform search on the basis of the <code>boundingPoly</code> and <code>bgColor</code>?</p>
  
  <p><strong>(2)</strong> Do I need to change the schema for performing the search or can I keep it as it is? What the best schema and mapping that suits my purpose?</p>
  
  <p><strong>(3)</strong> Also, I would like to perform a search on the basis of <code>bgColor</code>. How can I achieve this?</p>
  
  <blockquote>
    <p>I tried with <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html" rel="nofollow noreferrer">Geo-shape query</a> but failed to implement it with the proper result. Also, there is a restriction in <code>Geo-shape query</code> that the values must lie between 90 - 180. I think that part we can handle by normalizing the values.</p>
  </blockquote>
  
  <p><em>Sample JSON:</em></p>
  
  <pre><code>{
      "responses": [{
          "textAnnotations": [{
                  "description": "were",
                  "boundingPoly": {
                      "vertices": [{
                              "x": 112,
                              "y": 5
                          },
                          {
                              "x": 333,
                              "y": 5
                          },
                          {
                              "x": 333,
                              "y": 93
                          },
                          {
                              "x": 112,
                              "y": 93
                          }
                      ],
                      "confidence": 99
                  },
                  "wordInfo": {
                      "length": 4,
                      "width": 221,
                      "height": 88,
                      "bgColor": [
                          255,
                          255,
                          251
                      ]
                  }
              },
              {
                  "description": "gonna",
                  "boundingPoly": {
                      "vertices": [{
                              "x": 338,
                              "y": 5
                          },
                          {
                              "x": 589,
                              "y": 5
                          },
                          {
                              "x": 589,
                              "y": 93
                          },
                          {
                              "x": 338,
                              "y": 93
                          }
                      ],
                      "confidence": 99
                  },
                  "wordInfo": {
                      "length": 5,
                      "width": 251,
                      "height": 88,
                      "bgColor": [
                          255,
                          255,
                          255
                      ]
                  }
              }
          ]
      }]
  }
  
  </code></pre>
  
  <p>Thanks in advance!</p>