# Trouble running ElasticSearch in java test with numeric facets and multiple shards

**URL:** <https://discuss.elastic.co/t/trouble-running-elasticsearch-in-java-test-with-numeric-facets-and-multiple-shards/15235>\
**Category:** Elasticsearch\
**Created:** [January 14, 2014, 4:08pm UTC](https://discuss.elastic.co/t/trouble-running-elasticsearch-in-java-test-with-numeric-facets-and-multiple-shards/15235 "2014-01-14T16:08:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_Nordvik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrik_nordvik/32/1096_2.png) [@Henrik\_Nordvik](https://discuss.elastic.co/u/Henrik_Nordvik)\
**Post date:** [January 14, 2014, 4:08pm UTC](https://discuss.elastic.co/t/trouble-running-elasticsearch-in-java-test-with-numeric-facets-and-multiple-shards/15235/1 "2014-01-14T16:08:06Z")

</div>

Hi,  
We seem to have stumbled on some issue while running queries against a  
local elasticsearch node under a JUnit test.

We've been able to create a small test case which demonstrates this.

The necessary prerequisites for the failure:

- 2 or more shards
- Any of the DFS search types
- A terms facet on a field with a "long" type in the mapping

We have tested it with elasticsearch 0.90.x, and different versions of java.

It doesn't always fail, e.g. we have one machine with an old java version  
(1.7.0\_07) where it works in IntelliJ, but not in maven.

When we run the test against the master-branch the test works, but not on  
the 0.90-branch.

```auto
public class MyTest {
    private Client client;

    @Before
    public void createNode() throws Exception {
        Settings nodeSettings = ImmutableSettings.settingsBuilder()
                .put("node.local", false)
                .put("path.data", "./target/elasticsearch-test/data")
                .put("path.work", "./target/elasticsearch-test/work")
                .put("path.logs", "./target/elasticsearch-test/logs")
                .put("index.number_of_shards", "2")
                .build();

        Node node = NodeBuilder.nodeBuilder().settings(nodeSettings).node();
        client = node.client();
    }

    @After
    public void cleanup() throws Exception {
        FileSystemUtils.deleteRecursively(new 
File("./target/elasticsearch-test/"), true);
    }

    @Test
    public void demonstrateFailure() throws Exception {

        IndexResponse indexResponse = client
                .prepareIndex("test-index", "test-type")
                .setSource("{ \"id\": 123, \"test-value\": 321 }")
                .setRefresh(true)
                .execute()
                .actionGet();

        SearchResponse searchResponse = client
                .prepareSearch("test-index")
                .setQuery(new MatchAllQueryBuilder())
                .addFacet(new 
TermsFacetBuilder("test-facet").field("test-value"))
                .setSearchType(SearchType.DFS_QUERY_AND_FETCH)
                .execute()
                .actionGet();

        System.out.println(searchResponse);

        assertEquals(searchResponse.getFailedShards(), 0); // Failing!
    }
}

```

Output from a failed run:

```auto
{
  "took" : 68,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 0,
    "failed" : 2,
    "failures" : [ {
      "index" : "test-index",
      "shard" : 0,
      "status" : 500,
      "reason" : "ElasticSearchException; nested: AssertionError; "
    }, {
      "index" : "test-index",
      "shard" : 1,
      "status" : 500,
      "reason" : "ElasticSearchException; nested: AssertionError; "
    } ]
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : []
  }
}

```

--

Regards,  
Henrik Nordvik

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b511afef-4461-477e-a46f-5c3c7f9cdedd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b511afef-4461-477e-a46f-5c3c7f9cdedd%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [January 14, 2014, 7:59pm UTC](https://discuss.elastic.co/t/trouble-running-elasticsearch-in-java-test-with-numeric-facets-and-multiple-shards/15235/2 "2014-01-14T19:59:57Z")

</div>

Here are my findings:

The assertion error is

Caused by: java.lang.AssertionError  
at  
org.elasticsearch.common.recycler.ThreadLocalRecycler$TV.release(ThreadLocalRecycler.java:84)  
at  
org.elasticsearch.search.facet.terms.longs.TermsLongFacetExecutor.buildFacet(TermsLongFacetExecutor.java:104)  
at org.elasticsearch.search.facet.FacetPhase.execute(FacetPhase.java:200)  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:129)  
at  
org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:357)

It works in ES \<= 0.90.3 but not in ES \> 0.90.3 (also not in ES 1.0.0+) and  
is specific to the combination of faceting with long values and DFS search  
type.

Number of shards does not matter.

mvn --version  
Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28  
04:15:32+0200)  
Maven home: /usr/share/maven  
Java version: 1.6.0\_65, vendor: Apple Inc.  
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home  
Default locale: de\_DE, platform encoding: MacRoman  
OS name: "mac os x", version: "10.8.5", arch: "x86\_64", family: "mac"

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFWjJiL%2BM%3DsSEOX2gOvepiJe164y0pzKQb-x4UUSqpM-g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFWjJiL%2BM%3DsSEOX2gOvepiJe164y0pzKQb-x4UUSqpM-g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:56am UTC](https://discuss.elastic.co/t/trouble-running-elasticsearch-in-java-test-with-numeric-facets-and-multiple-shards/15235/3 "2017-07-06T01:56:48Z")

</div>


