title: Cloudant Search Queries Index Function
body: <p>I can't find very much documentation on how to properly define the index function such that I can do a full text search on the information that I need.</p>
  
  <p>I've used the Alchemy API to add "entities" json to my documents.
  For instance, I have a document with the following:</p>
  
  <pre><code>"_id": "redacted",
  "_rev": "redacted",
  "session": "20152016",
  "entities": [
  
  
      {
        "relevance": "0.797773",
        "count": "3",
        "type": "Organization",
        "text": "California Constitution"
      },
      {
        "relevance": "0.690092",
        "count": "1",
        "type": "Organization",
        "text": "Governors Highway Safety Association"
      }
  ]
  </code></pre>
  
  <p>I haven't been able to find any code snippets showing how to construct a search index function that looks at nested json.</p>
  
  <p>My stab at indexing the whole object appears to be incorrect.
  This is the full design document:</p>
  
  <pre><code>    {
    "_id": "_design/entities",
    "_rev": "redacted",
    "views": {},
    "language": "javascript",
    "indexes": {
      "entities": {
        "analyzer": "standard",
        "index": "function (doc) {\n  if (doc.entities.relevance &gt; 0.5){\n      index(\"default\", doc.entities.text, {\"store\":\"yes\"});\n  }\n\n}"
      }
    }
  }
  </code></pre>
  
  <p>And the search index formatted a little bit more clearly is </p>
  
  <pre><code>function (doc) {
    if (doc.entities.relevance &gt; 0.5){
        index("default", doc.entities.text, {"store":"yes"});
    }
  
  }
  </code></pre>
  
  <hr>
  
  <p>Adding the for loop as suggested below makes a lot of sense.
  However, I still am not able to return any results.
  My query is 
  "<a href="https://user.cloudant.com/calbills/_design/entities/_search/entities?q=Governors" rel="nofollow">https://user.cloudant.com/calbills/_design/entities/_search/entities?q=Governors</a>"</p>
  
  <p>Server response is:
  {"total_rows":0,"bookmark":"g2o","rows":[]}</p>