IndexMissingException with java client


(my3sons) #1

Hello,

I have created an index called catalog using http/curl (see below).
However, when I then try to access that index using java client (see code
below) it can't find it. What am I missing?

public static void main(String[] args) {
Node node = NodeBuilder.nodeBuilder().node();
Client client = node.client();

    SearchResponse response = client.prepareSearch("catalog")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(termQuery("name", "samsung"))
            .setFrom(0).setSize(10).setExplain(true)
            .setScroll(new TimeValue(600000))
            .execute()
            .actionGet();

    System.out.println(response.toString());

(my3sons) #2

Sorry, I just realized I did not include my index config/mappings. I have posted them below. The index is fully populated and I get back results using REST, but still can't connect using java client.

curl -XPOST localhost:9200/catalog -d '
{"index":
{ "number_of_shards": 2,
"number_of_replicas" : 1
}
}
}'

curl -XPUT localhost:9200/catalog/prods/_mapping -d '{

"terms" : {
"properties" : {
"name" : {
"type" : "multi_field",
"fields" : {
"name" : {"type" : "string", "index" : "analyzed", "includeInAll" : true},
"sortName" : {"type" : "string", "index" : "not_analyzed", "includeInAll" : false}
}
},
"shortDescription" : {
"type" : "string",
"index" : "analyzed",
"includeInAll" : true
},
"salePrice" : {
"type" : "double",
"index" : "analyzed",
"includeInAll" : false
},
"sku" : {
"type" : "integer",
"index" : "no",
"includeInAll" : false
},
"modelNumber" : {
"type" : "string",
"index" : "no",
"includeInAll" : true
},
"manufacturer" : {
"type" : "multi_field",
"fields" : {
"manufacturer" : {"type" : "string", "index" : "analyzed", "includeInAll" : true},
"rawBrand" : {"type" : "string", "index" : "not_analyzed", "includeInAll" : false}
}
},
"primaryCategoryName" : {
"type" : "multi_field",
"fields" : {
"primaryCategoryName" : {"type" : "string", "index" : "analyzed", "includeInAll" : false},
"rawPrimaryCategoryName" : {"type" : "string", "index" : "not_analyzed", "includeInAll" : false}
}
},
"store" : {
"type" : "string",
"index" : "analyzed",
"includeInAll" : false
},
"features": {
"type": "object",
"properties": {
"feature" : {"type" : "string", "includeInAll" : false}
}
},
"categoryPath": {
"type": "object",
"properties": {
"name" : {"type" : "string", "includeInAll" : false},
"id" : {"type" : "string", "includeInAll" : false}
}
}

}
  }
}

}'


(Igor Motov) #3

Your code is creating another full elasticsearch node instead of a client
node. It should be

Node node = NodeBuilder.nodeBuilder().client(true).node();

See http://www.elasticsearch.org/guide/reference/java-api/client.html for
an example.

On Friday, April 13, 2012 2:41:24 PM UTC-4, my3sons wrote:

Sorry, I just realized I did not include my index config/mappings. I have
posted them below. The index is fully populated and I get back results
using
REST, but still can't connect using java client.

curl -XPOST localhost:9200/catalog -d '
{"index":
{ "number_of_shards": 2,
"number_of_replicas" : 1
}
}
}'

curl -XPUT localhost:9200/catalog/prods/_mapping -d '{

"terms" : {
"properties" : {
"name" : {
"type" : "multi_field",
"fields" : {
"name" : {"type" : "string", "index" : "analyzed",
"includeInAll" : true},
"sortName" : {"type" : "string", "index" :
"not_analyzed",
"includeInAll" : false}
}
},
"shortDescription" : {
"type" : "string",
"index" : "analyzed",
"includeInAll" : true
},
"salePrice" : {
"type" : "double",
"index" : "analyzed",
"includeInAll" : false
},
"sku" : {
"type" : "integer",
"index" : "no",
"includeInAll" : false
},
"modelNumber" : {
"type" : "string",
"index" : "no",
"includeInAll" : true
},
"manufacturer" : {
"type" : "multi_field",
"fields" : {
"manufacturer" : {"type" : "string", "index" :
"analyzed",
"includeInAll" : true},
"rawBrand" : {"type" : "string", "index" :
"not_analyzed",
"includeInAll" : false}
}
},
"primaryCategoryName" : {
"type" : "multi_field",
"fields" : {
"primaryCategoryName" : {"type" : "string", "index" :
"analyzed", "includeInAll" : false},
"rawPrimaryCategoryName" : {"type" : "string", "index" :
"not_analyzed", "includeInAll" : false}
}
},
"store" : {
"type" : "string",
"index" : "analyzed",
"includeInAll" : false
},
"features": {
"type": "object",
"properties": {
"feature" : {"type" : "string", "includeInAll" : false}
}
},
"categoryPath": {
"type": "object",
"properties": {
"name" : {"type" : "string", "includeInAll" : false},
"id" : {"type" : "string", "includeInAll" : false}
}
}

    }
  }
}

}'

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-with-java-client-tp3908215p3908722.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(my3sons) #4

Thanks Igor!

I did try what you suggested, but still got the same error. However, I did then implement a TransportClient using the below and I got back the results I was expecting. I guess I need to dig into the details of the different clients more to better understand their behavior :slight_smile:

  Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

(Shay Banon) #5

The reason why you get IndexMissing is that for some reason, the node
client can't form a cluster with the other node you started (default to use
multicast discovery), so it forms its "own" cluster.

On Sat, Apr 14, 2012 at 12:13 AM, my3sons carey.boldenow@gmail.com wrote:

Thanks Igor!

I did try what you suggested, but still got the same error. However, I did
then implement a TransportClient using the below and I got back the results
I was expecting. I guess I need to dig into the details of the different
clients more to better understand their behavior :slight_smile:

 Client client = new TransportClient().addTransportAddress(new

InetSocketTransportAddress("localhost", 9300));

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-with-java-client-tp3908215p3909001.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #6