Elasticsearch-carrot2 JAVA API call


(Petr Janský) #1

Hello,

I use elasticsearch-carrot2https://github.com/carrot2/elasticsearch-carrot2and I was not able to find how to get cluster result using JAVA API e.g. for

GET _search_with_clusters?pretty=true
{
"query" : {
"bool": {
"must": [
{ "term": { "content": "zeman"}}
]
}
},
"query_hint": "vodafone",
"field_mapping": {
"url": ["_source.reference"],
"title": ["_source.title"],
"content": ["_source.content"]
}
}

result

{
"took": 12,
"timed_out": false,
"_shards": {
"total": 49,
"successful": 49,
"failed": 0
},
"hits": {
"total": 2080562,
"max_score": 1,
"hits": [.....]
},
"clusters": [
{
"id": 0,
"score": 4.094963866819582,
"label": "Možné Scénáře",
"phrases": [
"Možné Scénáře"
],
"documents": [

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114206",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114186",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114174"
]
},
....
],
"info": {
"algorithm": "lingo",
"search-millis": "11",
"clustering-millis": "26",
"total-millis": "38",
"include-hits": "true"
}
}

is there any way how call this query using JAVA API?

Thx
Petr

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7a23e5a5-15ed-40be-80d9-fa93eebc28fe%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Dawid Weiss) #2

In short: yes. Perhaps the best way to check out how to use Java API
is to look at unit tests. For example:

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L65

I would also use a language code field and mapping for Czech; this
should improve your clustering results (especially if you tweak the
default lexical resources in Carrot2... patches welcome :).

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L100

Dawid

On Wed, Mar 5, 2014 at 10:53 AM, Petr Janský petr.jansky@6hats.cz wrote:

Hello,

I use elasticsearch-carrot2 and I was not able to find how to get cluster
result using JAVA API e.g. for

GET _search_with_clusters?pretty=true
{
"query" : {
"bool": {
"must": [
{ "term": { "content": "zeman"}}
]
}
},
"query_hint": "vodafone",
"field_mapping": {
"url": ["_source.reference"],
"title": ["_source.title"],
"content": ["_source.content"]
}
}

result

{
"took": 12,
"timed_out": false,
"_shards": {
"total": 49,
"successful": 49,
"failed": 0
},
"hits": {
"total": 2080562,
"max_score": 1,
"hits": [.....]
},
"clusters": [
{
"id": 0,
"score": 4.094963866819582,
"label": "Možné Scénáře",
"phrases": [
"Možné Scénáře"
],
"documents": [

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114206",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114186",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114174"
]
},
....
],
"info": {
"algorithm": "lingo",
"search-millis": "11",
"clustering-millis": "26",
"total-millis": "38",
"include-hits": "true"
}
}

is there any way how call this query using JAVA API?

Thx
Petr

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/7a23e5a5-15ed-40be-80d9-fa93eebc28fe%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAM21Rt-PXv1DjckL_t5yvUrip_pLr%3DyL2R2LPWSYidtdbjBOig%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Petr Janský) #3

Hi Dawid,

thank you for your reply. I tried the sample you sent me
https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L65

but I got
Exception in thread "main"
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:
Failed execution
at
org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)
at
org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)
at
es.search.ClusteringActionTests.testAttributes(ClusteringActionTests.java:85)
at es.search.ClusteringActionTests.main(ClusteringActionTests.java:61)
Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast
to java.util.Map
at
org.elasticsearch.common.io.stream.StreamInput.readMap(StreamInput.java:319)
at
org.carrot2.elasticsearch.ClusteringAction$ClusteringActionRequest.readFrom(ClusteringAction.java:407)
at
org.elasticsearch.transport.netty.MessageChannelHandler.handleRequest(MessageChannelHandler.java:209)
at
org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:109)
at
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
at
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at
org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

I use
Elasticsearch 0.9.10
elasticsearch-carrot2 1.2.2
used jars from elasticsearch-carrot2-1.2.0.zip

thx
Petr

Dne středa, 5. března 2014 13:03:01 UTC+1 Dawid Weiss napsal(a):

In short: yes. Perhaps the best way to check out how to use Java API
is to look at unit tests. For example:

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L65

I would also use a language code field and mapping for Czech; this
should improve your clustering results (especially if you tweak the
default lexical resources in Carrot2... patches welcome :).

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L100

Dawid

On Wed, Mar 5, 2014 at 10:53 AM, Petr Janský <petr....@6hats.cz<javascript:>>
wrote:

Hello,

I use elasticsearch-carrot2 and I was not able to find how to get
cluster
result using JAVA API e.g. for

GET _search_with_clusters?pretty=true
{
"query" : {
"bool": {
"must": [
{ "term": { "content": "zeman"}}
]
}
},
"query_hint": "vodafone",
"field_mapping": {
"url": ["_source.reference"],
"title": ["_source.title"],
"content": ["_source.content"]
}
}

result

{
"took": 12,
"timed_out": false,
"_shards": {
"total": 49,
"successful": 49,
"failed": 0
},
"hits": {
"total": 2080562,
"max_score": 1,
"hits": [.....]
},
"clusters": [
{
"id": 0,
"score": 4.094963866819582,
"label": "Možné Scénáře",
"phrases": [
"Možné Scénáře"
],
"documents": [

"
http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114206",

"
http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114186",

"
http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114174"

     ] 
  }, 
 .... 

],
"info": {
"algorithm": "lingo",
"search-millis": "11",
"clustering-millis": "26",
"total-millis": "38",
"include-hits": "true"
}
}

is there any way how call this query using JAVA API?

Thx
Petr

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/elasticsearch/7a23e5a5-15ed-40be-80d9-fa93eebc28fe%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/60764a12-9734-402d-8b07-54bb55082444%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Dawid Weiss) #4

There is probably some inconsistency in your configuration -- the
exception you're getting indicates you serialize with a different
plugin version than serialize...

I just checked all the tests again and they pass. Make sure you have a
consistent configuration.

Dawid

On Wed, Mar 5, 2014 at 1:32 PM, Petr Janský petr.jansky@6hats.cz wrote:

Hi Dawid,

thank you for your reply. I tried the sample you sent me
https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L65

but I got
Exception in thread "main"
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:
Failed execution
at
org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)
at
org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)
at
es.search.ClusteringActionTests.testAttributes(ClusteringActionTests.java:85)
at es.search.ClusteringActionTests.main(ClusteringActionTests.java:61)
Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to
java.util.Map
at
org.elasticsearch.common.io.stream.StreamInput.readMap(StreamInput.java:319)
at
org.carrot2.elasticsearch.ClusteringAction$ClusteringActionRequest.readFrom(ClusteringAction.java:407)
at
org.elasticsearch.transport.netty.MessageChannelHandler.handleRequest(MessageChannelHandler.java:209)
at
org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:109)
at
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
at
org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
at
org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at
org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at
org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at
org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at
org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

I use
Elasticsearch 0.9.10
elasticsearch-carrot2 1.2.2
used jars from elasticsearch-carrot2-1.2.0.zip

thx
Petr

Dne středa, 5. března 2014 13:03:01 UTC+1 Dawid Weiss napsal(a):

In short: yes. Perhaps the best way to check out how to use Java API
is to look at unit tests. For example:

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L65

I would also use a language code field and mapping for Czech; this
should improve your clustering results (especially if you tweak the
default lexical resources in Carrot2... patches welcome :).

https://github.com/carrot2/elasticsearch-carrot2/blob/master/src/test/java/org/carrot2/elasticsearch/ClusteringActionTests.java#L100

Dawid

On Wed, Mar 5, 2014 at 10:53 AM, Petr Janský petr....@6hats.cz wrote:

Hello,

I use elasticsearch-carrot2 and I was not able to find how to get
cluster
result using JAVA API e.g. for

GET _search_with_clusters?pretty=true
{
"query" : {
"bool": {
"must": [
{ "term": { "content": "zeman"}}
]
}
},
"query_hint": "vodafone",
"field_mapping": {
"url": ["_source.reference"],
"title": ["_source.title"],
"content": ["_source.content"]
}
}

result

{
"took": 12,
"timed_out": false,
"_shards": {
"total": 49,
"successful": 49,
"failed": 0
},
"hits": {
"total": 2080562,
"max_score": 1,
"hits": [.....]
},
"clusters": [
{
"id": 0,
"score": 4.094963866819582,
"label": "Možné Scénáře",
"phrases": [
"Možné Scénáře"
],
"documents": [

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114206",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114186",

"http://www.denik.cz/z_domova/palestinsky-velvyslanec-zemrel-v-nemocnici-na-misto-jede-policejni-sef-cervicek.html#2114174"
]
},
....
],
"info": {
"algorithm": "lingo",
"search-millis": "11",
"clustering-millis": "26",
"total-millis": "38",
"include-hits": "true"
}
}

is there any way how call this query using JAVA API?

Thx
Petr

--
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 elasticsearc...@googlegroups.com.
To view this discussion on the web visit

https://groups.google.com/d/msgid/elasticsearch/7a23e5a5-15ed-40be-80d9-fa93eebc28fe%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/60764a12-9734-402d-8b07-54bb55082444%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAM21Rt-AdHYKxiQktq9s0WGQN6R-qZzA%3DNfOQpPXqr7c6iF%3DRg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #5