# Indexing property using an alias in elasticsearch

**URL:** <https://discuss.elastic.co/t/indexing-property-using-an-alias-in-elasticsearch/32080>\
**Category:** Elasticsearch\
**Created:** [October 13, 2015, 11:37am UTC](https://discuss.elastic.co/t/indexing-property-using-an-alias-in-elasticsearch/32080 "2015-10-13T11:37:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [October 13, 2015, 11:37am UTC](https://discuss.elastic.co/t/indexing-property-using-an-alias-in-elasticsearch/32080/1 "2015-10-13T11:37:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:45pm UTC](https://discuss.elastic.co/t/indexing-property-using-an-alias-in-elasticsearch/32080/2 "2017-07-05T23:45:07Z")

</div>


