@Test
  public void testNotLikeWithOtherIndexedField2() throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();

    Region region = cache.createRegion("pos", regionAttributes);
    int size = 10;

    String base = "abc";
    for (int i = 1; i <= size; i++) {
      Portfolio pf = new Portfolio(i);
      pf.pkid = "1";
      if ((i % 4) == 0) {
        pf.status = base;
      } else if ((i <= 2)) {
        pf.pkid = "2";
      }
      region.put(i, pf);
    }

    QueryService qs = cache.getQueryService();

    Query q =
        qs.newQuery(" SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%')");
    SelectResults results = (SelectResults) q.execute();
    int expectedResultSize = 2;
    if (results.size() != expectedResultSize * 4) {
      fail("Unexpected result. expected :" + expectedResultSize * 4 + " found : " + results.size());
    }

    q = qs.newQuery(" SELECT  *  FROM " + SEPARATOR
        + "pos ps WHERE NOT (ps.status like '%b%' or ps.pkid = '2')");
    results = (SelectResults) q.execute();
    if (results.size() != (expectedResultSize * 3)) {
      fail("Unexpected result. expected :" + (expectedResultSize * 3) + " found : "
          + results.size());
    }

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%' or ps.ID > 0 )");
    results = (SelectResults) q.execute();
    if (results.size() != 0) {
      fail("Unexpected result. expected :" + 0 + " found : " + results.size());
    }

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%') or ps.ID > 4 ");
    results = (SelectResults) q.execute();
    if (results.size() != 9) {
      fail("Unexpected result. expected :" + 9 + " found : " + results.size());
    }

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%' and ps.ID > 3 )");
    results = (SelectResults) q.execute();
    if (results.size() != 8) {
      fail("Unexpected result. expected :" + 5 + " found : " + results.size());
    }

    // Query to be compared with indexed results.
    q = qs.newQuery(" SELECT  *  FROM " + SEPARATOR
        + "pos ps WHERE NOT (ps.status like '%b%' and ps.pkid = '1' )");
    SelectResults expectedResults = (SelectResults) q.execute();
    if (expectedResults.size() != 8) {
      fail("Unexpected result. expected :" + size + " found : " + expectedResults.size());
    }

    // Create Index
    qs.createIndex("pkid", IndexType.FUNCTIONAL, "ps.pkid", SEPARATOR + "pos ps");
    qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", SEPARATOR + "pos ps");
    qs.createIndex("id", IndexType.FUNCTIONAL, "ps.ID", SEPARATOR + "pos ps");

    results = (SelectResults) q.execute();
    SelectResults[][] rs = new SelectResults[][] {{results, expectedResults}};

    if (results.size() != expectedResults.size()) {
      fail("Unexpected result. expected :" + expectedResults.size() + " found : " + results.size());
    }
    // compare results.
    CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%' and ps.ID > 3 )");
    results = (SelectResults) q.execute();
    if (results.size() != 8) {
      fail("Unexpected result. expected :" + 5 + " found : " + results.size());
    }

    // Index will only be used in OR junctions if NOT is used with LIKE.
    QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {
      private boolean indexCalled = false;

      @Override
      public void afterIndexLookup(Collection results) {
        indexCalled = true;
      }

      @Override
      public void endQuery() {
        assertTrue(indexCalled);
      }
    });

    q = qs.newQuery(" SELECT  *  FROM " + SEPARATOR
        + "pos ps WHERE NOT (ps.status like '_b_' or ps.pkid = '2')");
    results = (SelectResults) q.execute();
    if (results.size() != (expectedResultSize * 3)) {
      fail("Unexpected result. expected :" + (expectedResultSize * 3) + " found : "
          + results.size());
    }

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%' or ps.ID > 0 )");
    results = (SelectResults) q.execute();
    if (results.size() != 0) {
      fail("Unexpected result. expected :" + 0 + " found : " + results.size());
    }

    q = qs.newQuery(
        " SELECT  *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like '%b%') or ps.ID > 4");
    results = (SelectResults) q.execute();
    if (results.size() != 9) {
      fail("Unexpected result. expected :" + 9 + " found : " + results.size());
    }

    QueryObserverHolder.setInstance(old);
  }
Query with index on other fields.
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/LikePredicateJUnitTest.java