Yo estaba corriendo mi primera elasticsearch caso de prueba, estoy utilizando Java como la perspectiva de solución para hacer elasticsearch experimento. funciona perfectamente bien en eclipse Modo de Depuración,

el modo de depuración resultado:

{postDate=2016-01-31T10:32:58.952Z, title=Posting, content=today's weather is hot, tags=[hashtag]}

Pero cuando lo intento en la Ejecución normal de la aplicación modo, me estoy haciendo de la siguiente excepción y no tengo idea de en todos los. Por favor me guía.

La siguiente excepción:

8253 [main] INFO  org.elasticsearch.node  - [Marc Spector] started
8257 [elasticsearch[Marc Spector][clusterService#updateTask][T#1]] DEBUG org.elasticsearch.index.store  - [Marc Spector] [facebook] using index.store.throttle.type [none], with index.store.throttle.max_bytes_per_sec [0b]
8273 [elasticsearch[Marc Spector][search][T#4]] DEBUG org.elasticsearch.action.search.type  - [Marc Spector] All shards failed for phase: [query]
RemoteTransportException[[Marc Spector][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IndexNotFoundException[no such index];
Caused by: [facebook] IndexNotFoundException[no such index]
at org.elasticsearch.indices.IndicesService.indexServiceSafe(IndicesService.java:310)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:635)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:617)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:368)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:368)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:365)
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:350)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "main" Failed to execute phase [query], all shards failed
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:228)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:174)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:821)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:799)
at org.elasticsearch.transport.TransportService$4.onFailure(TransportService.java:361)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
8278 [elasticsearch[Marc Spector][clusterService#updateTask][T#1]] DEBUG org.elasticsearch.index.mapper  - [Marc Spector] [facebook] using dynamic[true]

El creo que muestra el código fuente puede ser más clara a la cuestión

Fuente:

Node node = nodeBuilder().clusterName("testing2").node(); 
Client client = node.client();
SearchResponse response = client.prepareSearch("facebook")
.setTypes("Lance")
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(QueryBuilders.matchPhrasePrefixQuery("title", "Pos"))
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
SearchHit[] searchResponse = response.getHits().getHits();
for(SearchHit hit : searchResponse){
System.out.println(hit.getSource());
}
  • No veo en cualquier parte del código donde se crea el índice facebook.

1 Comentario

  1. 4

    Antes de consultar su facebook índice, es necesario crear primero:

    Settings indexSettings = ImmutableSettings.settingsBuilder()
    .put("number_of_shards", 5)
    .put("number_of_replicas", 1)
    .build();
    CreateIndexRequest indexRequest = new CreateIndexRequest("facebook", indexSettings);
    client.admin().indices().create(indexRequest).actionGet();

    Y si usted espera encontrar algunos de los resultados, usted necesita para indexar sus datos también:

    IndexResponse response = client.prepareIndex("facebook", "Lance", "1")
    .setSource(jsonBuilder()
    .startObject()
    .field("title", "Posting")
    .field("postDate", new Date())
    .field("content", "today's weather is hot")
    .field("tags", Lists.newArrayList("hashtag"))
    .endObject()
    )
    .execute()
    .actionGet();

    A continuación, puede buscar en el índice.

    Espero que esta ayuda

Dejar respuesta

Please enter your comment!
Please enter your name here