# Is it possible to produce a “Temporary Field” during a search request?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-produce-a-temporary-field-during-a-search-request/43741>\
**Category:** Elasticsearch\
**Created:** [March 8, 2016, 9:12am UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-temporary-field-during-a-search-request/43741 "2016-03-08T09:12:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@Eric](https://discuss.elastic.co/u/Eric)\
**Post date:** [March 8, 2016, 9:12am UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-temporary-field-during-a-search-request/43741/1 "2016-03-08T09:12:42Z")

</div>

Sample Document:

```
{
    "text": "this is my text",
    "categories": [
        {"category": "sample category"},
        {"category": "local news"}
    ]
}

```

The mapping currently is:

```
{
    "topic": {
        "properties": {
            "categories": {
                "properties": {
                    "category": {
                        "type": "string",
                        "store": "no",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "ik_max_word",
                        "search_analyzer": "ik_max_word",
                        "include_in_all": "true",
                        "boost": 8,
                        "fields": {
                            "raw": {
                                "type": "string",
                                "index": "not_analyzed"
                            }
                        }
                    }
                }
            }
        }
    }
}

```

Search query:

```
{
    "_source": false,
    "query":{
        "match":{
            "categories.category":"news"
        }
    },
    "aggs": {
        "match_count": {
            "terms" : {"field": "categories.category.raw"}
        }
    }
}

```

The result I want it to be:

```
{
    ...
    "buckets": [
        {
            "key": "local news",
            "doc_count": 1
        } 
       
    ]
    ...
}

```

The result actually is (it aggregates all matching documents' categories.category):

```
{
    ...
    "buckets": [
        {
            "key": "local news",
            "doc_count": 1
        },{
            "key": "sample category", //THIS PART IS NOT NEEDED
            "doc_count": 1
        }
    ]
    ...
}

```

Is it possible to add a `temporary field` during a search? In this case let's say name all the matching `categories.category` as `categories.match_category`, and aggregates by this temporary field `categories.match_category`? If true how can I do it and if not what should I do then?

---

<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:10pm UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-temporary-field-during-a-search-request/43741/2 "2017-07-05T23:10:28Z")

</div>

Closed on July 5, 2017, 11:10pm UTC


