0

I have a search index, products, containing a field named tags, which is an array. Tags values appears in results when I don't add a fields section to my query, but when I do, it's just ignored outright, and doesn't appear in results, as shown below.

$ curl -XPOST 'http://localhost:9200/products/_search?pretty' -d '{  "query": {"match_all": {} }, "fields": ["tags", "id", "slug"], "size": 2}'
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 321826,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "products",
      "_type" : "products",
      "_id" : "39969794",
      "_score" : 1.0,
      "fields" : {
        "id" : [ "39969794" ],
        "slug" : [ "slug-39969794" ]
      }
    }, {
      "_index" : "products",
      "_type" : "products",
      "_id" : "21296413",
      "_score" : 1.0,
      "fields" : {
        "id" : [ "21296413" ],
        "slug" : [ "slug-21296413" ]
      }
    } ]
  }
}

Is there a reason or known issue for this? Is tags some kind of reserved word for ElasticSearch?

I'm using ES version 1.1.2 (Lucene 4.7).

1
  • 1
    Can you post the mapping for for the products index? And maybe the source for those two docs? Commented Feb 18, 2015 at 16:32

2 Answers 2

1

tags is not an ES reserved word. So that's not your problem.

Is your tags an array of atomic types (numbers, strings or booleans)? Or is it an array of objects?

fields only works with leaf nodes. So "fields": ["tags"] should work fine with an array of strings but it would fail with an array of tag objects.

Sign up to request clarification or add additional context in comments.

Comments

0

Confused as to why you are using "fields" instead of "terms?"

$ curl -XPOST 'http://localhost:9200/products/_search?pretty' -d 
 '{"query": 
    {
    "match_all": {} 
    }, 
   "terms": ["tags", "id", "slug"],
   "size": 2}'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.