public CacheSerializableRunnable getCacheSerializableRunnableForDefineIndex(
      final String prRegionName, final ArrayList<String> indexName,
      final ArrayList<String> indexedExpression, final ArrayList<String> fromClause) {

    SerializableRunnable prIndexCreator = new CacheSerializableRunnable("PartitionedIndexCreator") {
      @Override
      public void run2() {
        List<Index> indexes = null;
        try {
          Cache cache = getCache();
          QueryService qs = cache.getQueryService();
          Region region = cache.getRegion(prRegionName);
          for (int i = 0; i < indexName.size(); i++) {
            qs.defineIndex(indexName.get(i), indexedExpression.get(i),
                fromClause == null ? region.getFullPath() : fromClause.get(i));
          }
          indexes = qs.createDefinedIndexes();
        } catch (Exception ex) {
          if (ex instanceof MultiIndexCreationException) {
            StringBuilder sb = new StringBuilder();
            for (Exception e : ((MultiIndexCreationException) ex).getExceptionsMap().values()) {
              sb.append(e.getMessage()).append("\n");
            }
            fail("Multi index creation failed, " + sb);
          } else {
            Assert.fail("Creating Index in this vm failed : ", ex);
          }
        }
        assertNotNull("Indexes should have been created.", indexes);
      }
    };
    return (CacheSerializableRunnable) prIndexCreator;
  }
This function defines a appropriate index on a PR given the name and other parameters.
geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRQueryDUnitHelper.java