majackson
majackson

Reputation: 2963

ElasticSearch ignoring field named 'tags' when specified in "fields"

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).

Upvotes: 0

Views: 492

Answers (2)

user7594840
user7594840

Reputation: 103

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}'

Upvotes: 0

jdh2550
jdh2550

Reputation: 33

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.

Upvotes: 1

Related Questions