Changing the field names of search results


(Mark Huang-2) #1

Hi,

I'm relatively new to elasticsearch, so please bare with me. I read
through the documentation for two days and tried to write my own mapper for
some sample data. I am the CouchDB River plugin to index my CouchDB
database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have a
gist at the following link:

If you look at the python code, I specified the fields that I want returned
from the search. However, I have to use the "dot notation" to specify
which field I want returned. Look at the "product.json" file to see a
rough structure of my indexed document. Things like ID and Key are on the
very outer level of the product document so it's fine to just refer to them
using they names directly. However, I have a content JSON object which
contains keys like brand, name, description, etc. These fields have to be
referenced using the dot notation like : "content.description" or
"content.brand".

The search results contain keys with the names being set with the "dot
notation". I will pass this resultset to my frontend and have my widget
framework (I use KendoUI) parse the data. However, it fails in Firebug
saying that content is undefined because the key name is "content.brand",
and the framework thinks that content is an object with an attribute brand
but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem to
work. * My question is: "Is there a way to change the output of the key
names to say, "brand" instead of "content.brand" ? "*
*
*
Am I confusing any of you? If so, please let me know, I'll be glad to
explain my problem again.

Regards,
Mark Huang

--


(Mark Huang-2) #2

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:

Hi,

I'm relatively new to elasticsearch, so please bare with me. I read
through the documentation for two days and tried to write my own mapper for
some sample data. I am the CouchDB River plugin to index my CouchDB
database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have a
gist at the following link:

https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want
returned from the search. However, I have to use the "dot notation" to
specify which field I want returned. Look at the "product.json" file to
see a rough structure of my indexed document. Things like ID and Key are
on the very outer level of the product document so it's fine to just refer
to them using they names directly. However, I have a content JSON object
which contains keys like brand, name, description, etc. These fields have
to be referenced using the dot notation like : "content.description" or
"content.brand".

The search results contain keys with the names being set with the "dot
notation". I will pass this resultset to my frontend and have my widget
framework (I use KendoUI) parse the data. However, it fails in Firebug
saying that content is undefined because the key name is "content.brand",
and the framework thinks that content is an object with an attribute brand
but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem
to work. * My question is: "Is there a way to change the output of the
key names to say, "brand" instead of "content.brand" ? "*
*
*
Am I confusing any of you? If so, please let me know, I'll be glad to
explain my problem again.

Regards,
Mark Huang

--


(David Pilato) #3

Have a look at scripts: https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang zhenghao12@gmail.com a écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:
Hi,

I'm relatively new to elasticsearch, so please bare with me. I read through the documentation for two days and tried to write my own mapper for some sample data. I am the CouchDB River plugin to index my CouchDB database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have a gist at the following link:

https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want returned from the search. However, I have to use the "dot notation" to specify which field I want returned. Look at the "product.json" file to see a rough structure of my indexed document. Things like ID and Key are on the very outer level of the product document so it's fine to just refer to them using they names directly. However, I have a content JSON object which contains keys like brand, name, description, etc. These fields have to be referenced using the dot notation like : "content.description" or "content.brand".

The search results contain keys with the names being set with the "dot notation". I will pass this resultset to my frontend and have my widget framework (I use KendoUI) parse the data. However, it fails in Firebug saying that content is undefined because the key name is "content.brand", and the framework thinks that content is an object with an attribute brand but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem to work. My question is: "Is there a way to change the output of the key names to say, "brand" instead of "content.brand" ? "

Am I confusing any of you? If so, please let me know, I'll be glad to explain my problem again.

Regards,
Mark Huang

--


(Mark Huang-2) #4

Sorry, I don't see how this helps. I did mention I am already using the
elastic search river couchdb plugin. I don't think it has anything to do
with this plugin.

On Sun, Aug 12, 2012 at 11:04 PM, David Pilato david@pilato.fr wrote:

Have a look at scripts:
https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang zhenghao12@gmail.com a écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:

Hi,

I'm relatively new to elasticsearch, so please bare with me. I read
through the documentation for two days and tried to write my own mapper for
some sample data. I am the CouchDB River plugin to index my CouchDB
database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have
a gist at the following link:

https://gist.github.com/**3325910 https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want
returned from the search. However, I have to use the "dot notation" to
specify which field I want returned. Look at the "product.json" file to
see a rough structure of my indexed document. Things like ID and Key are
on the very outer level of the product document so it's fine to just refer
to them using they names directly. However, I have a content JSON object
which contains keys like brand, name, description, etc. These fields have
to be referenced using the dot notation like : "content.description" or
"content.brand".

The search results contain keys with the names being set with the "dot
notation". I will pass this resultset to my frontend and have my widget
framework (I use KendoUI) parse the data. However, it fails in Firebug
saying that content is undefined because the key name is "content.brand",
and the framework thinks that content is an object with an attribute brand
but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem
to work. * My question is: "Is there a way to change the output of the
key names to say, "brand" instead of "content.brand" ? "*
*
*
Am I confusing any of you? If so, please let me know, I'll be glad to
explain my problem again.

Regards,
Mark Huang

--

--

--


(David Pilato) #5

Try something like:
{ "type" : "couchdb", "couchdb" : { "script" : "ctx.doc.brand = ctx.doc.content.brand;ctx.doc.content.brand=null;" } }
Does it help?

--

Le 12 août 2012 à 17:16, Zhenghao Huang zhenghao12@gmail.com a écrit :

Sorry, I don't see how this helps. I did mention I am already using the elastic search river couchdb plugin. I don't think it has anything to do with this plugin.

On Sun, Aug 12, 2012 at 11:04 PM, David Pilato david@pilato.fr wrote:
Have a look at scripts: https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang zhenghao12@gmail.com a écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:
Hi,

I'm relatively new to elasticsearch, so please bare with me. I read through the documentation for two days and tried to write my own mapper for some sample data. I am the CouchDB River plugin to index my CouchDB database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have a gist at the following link:

https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want returned from the search. However, I have to use the "dot notation" to specify which field I want returned. Look at the "product.json" file to see a rough structure of my indexed document. Things like ID and Key are on the very outer level of the product document so it's fine to just refer to them using they names directly. However, I have a content JSON object which contains keys like brand, name, description, etc. These fields have to be referenced using the dot notation like : "content.description" or "content.brand".

The search results contain keys with the names being set with the "dot notation". I will pass this resultset to my frontend and have my widget framework (I use KendoUI) parse the data. However, it fails in Firebug saying that content is undefined because the key name is "content.brand", and the framework thinks that content is an object with an attribute brand but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem to work. My question is: "Is there a way to change the output of the key names to say, "brand" instead of "content.brand" ? "

Am I confusing any of you? If so, please let me know, I'll be glad to explain my problem again.

Regards,
Mark Huang

--

--

--


(Mark Huang-2) #6

Ok...so you mean, if I want something within content to have an output
field name without the dot-notation, I have to remap it to the first level
using script?

That seems rather tedious...I'll give it a try thanks. There has to be a
much better way of doing this right?!

On Monday, 13 August 2012 00:15:46 UTC+8, David Pilato wrote:

Try something like:

{
"type" : "couchdb",
"couchdb" : {
"script" : "ctx.doc.brand = ctx.doc.content.brand;ctx.doc.content.brand=null;"
}
}

Does it help?

--

Le 12 août 2012 à 17:16, Zhenghao Huang <zheng...@gmail.com <javascript:>>
a écrit :

Sorry, I don't see how this helps. I did mention I am already using the
elastic search river couchdb plugin. I don't think it has anything to do
with this plugin.

On Sun, Aug 12, 2012 at 11:04 PM, David Pilato <da...@pilato.fr<javascript:>

wrote:

Have a look at scripts:
https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang <zheng...@gmail.com <javascript:>> a
écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:

Hi,

I'm relatively new to elasticsearch, so please bare with me. I read
through the documentation for two days and tried to write my own mapper for
some sample data. I am the CouchDB River plugin to index my CouchDB
database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have
a gist at the following link:

https://gist.github.com/**3325910 https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want
returned from the search. However, I have to use the "dot notation" to
specify which field I want returned. Look at the "product.json" file to
see a rough structure of my indexed document. Things like ID and Key are
on the very outer level of the product document so it's fine to just refer
to them using they names directly. However, I have a content JSON object
which contains keys like brand, name, description, etc. These fields have
to be referenced using the dot notation like : "content.description" or
"content.brand".

The search results contain keys with the names being set with the "dot
notation". I will pass this resultset to my frontend and have my widget
framework (I use KendoUI) parse the data. However, it fails in Firebug
saying that content is undefined because the key name is "content.brand",
and the framework thinks that content is an object with an attribute brand
but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem
to work. * My question is: "Is there a way to change the output of the
key names to say, "brand" instead of "content.brand" ? "*
*
*
Am I confusing any of you? If so, please let me know, I'll be glad to
explain my problem again.

Regards,
Mark Huang

--

--

--

--


(David Pilato) #7

Yes. My opinion is that you should index documents as you want to retrieve it after. So I will do it that way.

My 2 cents.
David

--

Le 12 août 2012 à 18:42, Mark Huang zhenghao12@gmail.com a écrit :

Ok...so you mean, if I want something within content to have an output field name without the dot-notation, I have to remap it to the first level using script?

That seems rather tedious...I'll give it a try thanks. There has to be a much better way of doing this right?!

On Monday, 13 August 2012 00:15:46 UTC+8, David Pilato wrote:
Try something like:
{ "type" : "couchdb", "couchdb" : { "script" : "ctx.doc.brand = ctx.doc.content.brand;ctx.doc.content.brand=null;"
}
}
Does it help?

--

Le 12 août 2012 à 17:16, Zhenghao Huang zheng...@gmail.com a écrit :

Sorry, I don't see how this helps. I did mention I am already using the elastic search river couchdb plugin. I don't think it has anything to do with this plugin.

On Sun, Aug 12, 2012 at 11:04 PM, David Pilato da...@pilato.fr wrote:
Have a look at scripts: https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang zheng...@gmail.com a écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:
Hi,

I'm relatively new to elasticsearch, so please bare with me. I read through the documentation for two days and tried to write my own mapper for some sample data. I am the CouchDB River plugin to index my CouchDB database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I have a gist at the following link:

https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want returned from the search. However, I have to use the "dot notation" to specify which field I want returned. Look at the "product.json" file to see a rough structure of my indexed document. Things like ID and Key are on the very outer level of the product document so it's fine to just refer to them using they names directly. However, I have a content JSON object which contains keys like brand, name, description, etc. These fields have to be referenced using the dot notation like : "content.description" or "content.brand".

The search results contain keys with the names being set with the "dot notation". I will pass this resultset to my frontend and have my widget framework (I use KendoUI) parse the data. However, it fails in Firebug saying that content is undefined because the key name is "content.brand", and the framework thinks that content is an object with an attribute brand but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't seem to work. My question is: "Is there a way to change the output of the key names to say, "brand" instead of "content.brand" ? "

Am I confusing any of you? If so, please let me know, I'll be glad to explain my problem again.

Regards,
Mark Huang

--

--

--

--


(Mark Huang-2) #8

Tested this today and it did solved my problem. But it created another
problem for me which I have just started a new threadhttps://groups.google.com/forum/?fromgroups#!topic/elasticsearch/S0bmeMvnLyQ[1-25]on. The problem I am facing is that, I want different fields for different
types. That would mean I have to index my database based on type. Am I
correct? I've been reading the docs here and there and I still can't
figure out a solution.

On Sunday, 12 August 2012 14:29:45 UTC-5, David Pilato wrote:

Yes. My opinion is that you should index documents as you want to retrieve
it after. So I will do it that way.

My 2 cents.
David

--

Le 12 août 2012 à 18:42, Mark Huang <zheng...@gmail.com <javascript:>> a
écrit :

Ok...so you mean, if I want something within content to have an output
field name without the dot-notation, I have to remap it to the first level
using script?

That seems rather tedious...I'll give it a try thanks. There has to be a
much better way of doing this right?!

On Monday, 13 August 2012 00:15:46 UTC+8, David Pilato wrote:

Try something like:

{
"type" : "couchdb",
"couchdb" : {
"script" : "ctx.doc.brand = ctx.doc.content.brand;ctx.doc.content.brand=null;"
}
}

Does it help?

--

Le 12 août 2012 à 17:16, Zhenghao Huang zheng...@gmail.com a écrit :

Sorry, I don't see how this helps. I did mention I am already using the
elastic search river couchdb plugin. I don't think it has anything to do
with this plugin.

On Sun, Aug 12, 2012 at 11:04 PM, David Pilato da...@pilato.fr wrote:

Have a look at scripts:
https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md

It should help.

David

--

Le 12 août 2012 à 16:51, Mark Huang zheng...@gmail.com a écrit :

Please, anyone can help?

On Sunday, August 12, 2012 1:56:24 AM UTC+8, Mark Huang wrote:

Hi,

I'm relatively new to elasticsearch, so please bare with me. I read
through the documentation for two days and tried to write my own mapper for
some sample data. I am the CouchDB River plugin to index my CouchDB
database. I also use Python's pyes library to query against elasticsearch.

I'm encountering a problem with my search results at the moment. I
have a gist at the following link:

https://gist.github.com/**3325910 https://gist.github.com/3325910

If you look at the python code, I specified the fields that I want
returned from the search. However, I have to use the "dot notation" to
specify which field I want returned. Look at the "product.json" file to
see a rough structure of my indexed document. Things like ID and Key are
on the very outer level of the product document so it's fine to just refer
to them using they names directly. However, I have a content JSON object
which contains keys like brand, name, description, etc. These fields have
to be referenced using the dot notation like : "content.description" or
"content.brand".

The search results contain keys with the names being set with the "dot
notation". I will pass this resultset to my frontend and have my widget
framework (I use KendoUI) parse the data. However, it fails in Firebug
saying that content is undefined because the key name is "content.brand",
and the framework thinks that content is an object with an attribute brand
but the search results actually have a key named "content.brand"!

I tried using the index_name attribute during mapping but it didn't
seem to work. * My question is: "Is there a way to change the output
of the key names to say, "brand" instead of "content.brand" ? "*
*
*
Am I confusing any of you? If so, please let me know, I'll be glad to
explain my problem again.

Regards,
Mark Huang

--

--

--

--

--


(system) #9