How to optimise MongoDB search with indexing?
<p>These documents are in my MongoDB collection:</p>

<pre><code>{
  "_id" : ObjectId("57f5e1b5c7739d9805edfe85"),
  "date" : ISODate("2016-10-01T00:00:00.000Z"),
  "query" : "test1",
  "page" : "page1/runway/ready-to-wear/ss17/2016/10/christian-dior/",
  "clicks" : 17.0,
  "impressions" : 161.0,
  "ctr" : 0.10559006211180125,
  "position" : 8.503105590062113
}
{
  "_id" : ObjectId("57f5e1b5c7739d9805edfe86"),
  "date" : ISODate("2016-10-01T00:00:00.000Z"),
  "query" : "test1",
  "page" : "page2/runway/ready-to-wear/ss17/2016/10/christian-dior/",
  "clicks" : 17.0,
  "impressions" : 161.0,
  "ctr" : 0.10559006211180125,
  "position" : 8.503105590062113
}
{
  "_id" : ObjectId("57f5e1b5c7739d9805edfe87"),
  "date" : ISODate("2016-10-01T00:00:00.000Z"),
  "query" : "test2",
  "page" : "page3/runway/ready-to-wear/ss17/2016/10/christian-dior/",
  "clicks" : 17.0,
  "impressions" : 161.0,
  "ctr" : 0.10559006211180125,
  "position" : 8.503105590062113
}
</code></pre>

<p>I need to filter and get some documents like these:</p>

<pre><code>{
  "_id" : ObjectId("57f5e1b5c7739d9805edfe85"),
  "date" : ISODate("2016-10-01T00:00:00.000Z"),
  "query" : "test1",
  "page" : "page1/runway/ready-to-wear/ss17/2016/10/christian-dior/",
  "clicks" : 17.0,
  "impressions" : 161.0,
  "ctr" : 0.10559006211180125,
  "position" : 8.503105590062113
}
{
  "_id" : ObjectId("57f5e1b5c7739d9805edfe86"),
  "date" : ISODate("2016-10-01T00:00:00.000Z"),
  "query" : "test1",
  "page" : "page2/runway/ready-to-wear/ss17/2016/10/christian-dior/",
  "clicks" : 17.0,
  "impressions" : 161.0,
  "ctr" : 0.10559006211180125,
  "position" : 8.503105590062113
}
</code></pre>

<p>I created an index using query field and ran <code>db.query</code> using <code>aggregate()</code> method like this:</p>

<pre><code>{ 
     "aggregate" : "Mycollection Name" ,
     "pipeline" : [ 
         { "$match" : { "$text" : { "$search" : "\"test1\""}}},
         { "$match" : { "date" : { "$gte" : { "$date" : "2016-10-  01T00:00:00.000Z"} ,"$lte" : { "$date" : "2016-10-01T00:00:00.000Z"}}}},
         { "$group" : { "_id" : "$page" , "clicks" : { "$sum" : "$clicks"} ,  "impressions" : { "$sum" : "$impressions"} , "ctr" : { "$avg" : "$ctr"} ,  "position" : { "$avg" : "$position"}}} , 
         { "$sort" : { "clicks" : -1}}
      ]
}
</code></pre>

<p>This query is working but it is not return exactly search.</p>

<p>How can I optimize this query?</p>