So I had this requirement which David Pilato solved for me:
https://groups.google.com/d/msg/elasticsearch/KRPldny3wUk/nrfJtkOsv-oJ
As you can see, a book may have a different output fields when compared
with a cd. And hence I wanted a way to index different types (matching my
couchdb type with Elasticsearch type) separately. If I were to use:
script: ctx._type = ctx.doc.type, I wouldn't be able to set the different
output fields per document type. Someone else told me that I could use
partial fields to accomplish this, is this right?
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
On Tuesday, 14 August 2012 00:39:51 UTC-5, Mark Huang wrote:
Damn....I feel so stupid for not realizing that this could be done. I
read about the Elasticsearch _type.....but wasn't sure what to make of it.
Thank you once again
On Tuesday, 14 August 2012 00:27:13 UTC-5, Dan Everton wrote:
On Tuesday, August 14, 2012 2:37:58 PM UTC+10, Mark Huang wrote:
What if after indexing the book type, I now want to index another type
called "cd". Do I just create a second _river definition? I tried
creating a second _river definition to index cd but nothing seemed to
happen. Help?
If everything's in the same CouchDB database you can just use a single
river definition and use a script on the Elasticsearch side to set the
type. So say you have a "type" field in your documents in CouchDB that is
also the same as the type you want to use in Elasticsearch. Your river
definition would look like this:
{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "amazon",
"script" : "ctx._type = ctx.doc.type"
},
"index" : {
"index" : "amazon"
}
}
Setting ctx._type tells Elasticsearch what type in the index to use. So
if doc.type for a CouchDB changeset is "book" then Elasticsearch will index
it as the "book" type. Obviously you can make the script a bit more
sophisticated if your types don't map one to one. I'm not aware of any way
to externalise that script unfortunately.
Cheers,
Dan
--