Hi,
I have an index in ES where one of the fields (say "tags") in the document
is actually a list. The way I index is roughly as below -
List<String> customActionList = new ArrayList<String>();
customActionList.add("tag1");
customActionList.add("tag2");
XContentBuilder xcb = jsonBuilder().startObject();
xcb = xcb.field("tag", customActionList);
xcb = xcb.endObject();
IndexResponse indexResponse =
irb.setSource(xcb).execute().actionGet();
but in the mapping, i dont see it as a list. it shows as a string. is that
fine?
curl -XGET 'http://localhost:9200///_mapping'
{:{"properties":{..."tags":{"type":"string"}...}
Assuming this is correct, how do i search for all documents which have a
tag, say "my_tag" in its "tags" list? I am not able to find the
documentation for this kind of search.
thanks
Yes, this is fine. You can search it the same way you search for fields
with a single value. To find all documents which have a tag "my_tag", just
search for tags:mytag.
It might be also useful to make this field not_analyzed to avoid issues
with tags that contain spaces and special characters.
On Monday, May 14, 2012 5:38:59 PM UTC-4, T Vinod Gupta wrote:
Hi,
I have an index in ES where one of the fields (say "tags") in the document
is actually a list. The way I index is roughly as below -
List<String> customActionList = new ArrayList<String>();
customActionList.add("tag1");
customActionList.add("tag2");
XContentBuilder xcb = jsonBuilder().startObject();
xcb = xcb.field("tag", customActionList);
xcb = xcb.endObject();
IndexResponse indexResponse =
irb.setSource(xcb).execute().actionGet();
but in the mapping, i dont see it as a list. it shows as a string. is that
fine?
curl -XGET 'http://localhost:9200///_mapping'
{:{"properties":{..."tags":{"type":"string"}...}
Assuming this is correct, how do i search for all documents which have a
tag, say "my_tag" in its "tags" list? I am not able to find the
documentation for this kind of search.
thanks