title: Invalid parameter index! You seem to have declare too little query method parameters! - Spring Mongo TextSearch
body: <p>I am developing <code>Spring + Mongo Data JPA</code> example for Text Search. When I am trying to search using <code>OrderID</code> 102. I was expecting all records to be fetch from DB those record contains 102 in <code>OrderID</code>. Please help me I see following error is coming.</p>
  
  <pre><code>org.springframework.data.repository.query.ParameterOutOfBoundsException: Invalid parameter index! You seem to have declare too little query method parameters!
      at org.springframework.data.repository.query.Parameters.getParameter(Parameters.java:178)
      at org.springframework.data.repository.query.Parameters.getBindableParameter(Parameters.java:248)
      at org.springframework.data.repository.query.ParametersParameterAccessor.getBindableValue(ParametersParameterAccessor.java:107)
      at org.springframework.data.repository.query.ParametersParameterAccessor$BindableParameterIterator.next(ParametersParameterAccessor.java:165)
      at org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor$ConvertingIterator.next(ConvertingParameterAccessor.java:176)
      at org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor$ConvertingIterator.nextConverted(ConvertingParameterAccessor.java:185)
      at org.springframework.data.mongodb.repository.query.MongoQueryCreator.from(MongoQueryCreator.java:244)
      at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:114)
      at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:58)
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
      at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
      at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.createQuery(PartTreeMongoQuery.java:76)
      at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:85)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:462)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy22.findByOrderId(Unknown Source)
      at com.common.index.OrderTest.testOrderSearch(OrderTest.java:29)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:70)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      at java.util.ArrayList.rangeCheck(ArrayList.java:653)
      at java.util.ArrayList.get(ArrayList.java:429)
      at org.springframework.data.repository.query.Parameters.getParameter(Parameters.java:176)
      ... 52 more
  </code></pre>
  
  <p>The code I developed:
  Order.java</p>
  
  <pre><code>@Document(collection="orders")
  public class Order {
  
      @Id
      private ObjectId id;
  
      @Field("OrderID")
      private Integer orderId;
  
      @Field("CustomerID")
      private String customerId;
  
      @Field("EmployeeID")
      private Integer employeeId;
  
      @Field("OrderDate")
      private String orderDate;
  
      @Field("RequiredDate")
      private String requiredDate;
  
      @Field("ShippedDate")
      private String shippedDate;
  
      @Field("ShipVia")
      private Integer shipVia;
  
      @Field("Freight")
      private Double freight;
  
      @Field("ShipName")
      private String shipName;
  
      @Field("ShipAddress")
      private Integer shipAddress;
  
      @Field("ShipCity")
      private String shipCity;
  
      @Field("ShipRegion")
      private String shipRegion;
  
      @Field("ShipPostalCode")
      private String shipPostalCode;
  
      @Field("ShipCountry")
      private Integer shipCountry;
  
      @Field("field14")
      private String field14;
  
          // setters and getters
  }
  </code></pre>
  
  <p>OrderRepository.java</p>
  
  <pre><code>public interface OrderRepository extends CrudRepository&lt;Order, Integer&gt;{
      List&lt;Order&gt; findByOrderId(TextCriteria criteria);
  }
  </code></pre>
  
  <p>This is to create Index in mongoDB:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:application-config.xml"})
  public class IndexToolTest {
  
      @Autowired
      private MongoTemplate mongoTemplate;
  
      @Test
      public void testCreateIndex() {
          mongoTemplate.indexOps(Order.class).ensureIndex(new TextIndexDefinitionBuilder()
          .onField("OrderID").build());
      }
  }
  </code></pre>
  
  <p>OrderTest.java</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:application-config.xml"})
  public class OrderTest {
      private static final Logger LOGGER = LoggerFactory.getLogger(OrderTest.class);
  
      @Autowired
      private OrderRepository orderRepository;
  
      @Test
      public void testOrderSearch() {
          TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("102");
          List&lt;Order&gt; orders = orderRepository.findByOrderId(criteria);
          System.out.println("Size : "+orders.size());
      }
  }
  </code></pre>
  
  <p>application-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xmlns:mongo="http://www.springframework.org/schema/data/mongo"
               xmlns:mvc="http://www.springframework.org/schema/mvc"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/data/mongo
      http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd"&gt;
  
      &lt;context:annotation-config/&gt;
      &lt;mvc:annotation-driven/&gt;
  
      &lt;beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;beans:property name="locations"&gt;
              &lt;beans:list&gt;
                  &lt;beans:value&gt;classpath:database.properties&lt;/beans:value&gt;
               &lt;/beans:list&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;context:component-scan base-package="com.common.model"/&gt;
  
      &lt;!-- Default bean name is 'mongo' --&gt;
      &lt;mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}"/&gt;
  
      &lt;mongo:repositories base-package="com.common.repository"/&gt;
  
      &lt;beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;beans:constructor-arg ref="mongo"/&gt;
          &lt;beans:constructor-arg name="databaseName" value="${mongo.database.name}"/&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="orderService" class="com.common.Service.OrderServiceImpl" /&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>I've provided all sufficient information. Please help now.
  <a href="https://i.stack.imgur.com/yVZgx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yVZgx.png" alt="enter image description here"></a></p>