Indexing property using an alias in elasticsearch


#1

Actually, I'm creating an alias per user:

curl -XPUT 'http://server/index/_alias/<user>' -d '
{
  "routing": "<user>",
  "filter": {
    "term": {
      "user": "<user>"   //user property must exists 
    }
  }
}'

curl -XPUT 'http://server/index/_mapping/inputs' -d ' {
  "inputs": {
    "properties": {
      "user": { "type": "string", "index": "not_analyzed" }
    }
  }
}'

So, it works fine, so it's usefull due I don't need to set user term for each search or get request.

The problem appears on indexing requests. I'm trying to do when I index a document using an alias, I want not only it's routed, I also want the new document contains the user property filled with username corresponding to the alias name.

Is it possible?

Example

curl -XPUT 'http://server/alias/type/1111' -d '
{
    "matter": "matter sample"
}'

I've added a new document using alias alias in type collection.
So I was expecting when I perform a search like:

curl -XGET 'http://server/alias/type/_search?q=*&pretty'
{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

As you can see, the result is empty.
So, I've tried to get the result without using the alias:

curl -XGET 'http://ESNode01:9201/index/type/_search?q=*&pretty'
{
  "took" : 820,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "index",
      "_type" : "type",
      "_id" : "1111",
      "_score" : 1.0,
      "_source":
      {
          "matter": "matter sample"
      }
    } ]
  }
}

So, the document appears now.


(system) #2