# Search among field names in Elasticsearch

**URL:** <https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674>\
**Category:** Elasticsearch\
**Created:** [January 24, 2019, 11:17pm UTC](https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674 "2019-01-24T23:17:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shankarps](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shankarps/32/78663_2.png) [@shankarps](https://discuss.elastic.co/u/shankarps)\
**Post date:** [January 24, 2019, 11:17pm UTC](https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674/1 "2019-01-24T23:17:23Z")

</div>

Is it possible to search on some fields with increased weights if a field name is present in search query?  
For example if an index has the following fields:

```
PUT /my_index
{
"mappings": {
    "_doc": {
        "properties": {
            "name": {
                "type": "keyword"
            },
            "pistons": {
                "type": "keyword"
            },
            "cylinders": { "type": "integer" }
        }
    }
}
}

```

and the search query is

> 10 cylinders

is there a way in Elasticsearch to focus this search to the "cylinders" field, since that field was mentioned on the query?

Or if the search is for

> metal pistons

can we narrow this search to the pistons field, based on the contents of the search query?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Tosh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tosh/32/29269_2.png) [@Tosh](https://discuss.elastic.co/u/Tosh)\
**Post date:** [January 25, 2019, 7:24am UTC](https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674/2 "2019-01-25T07:24:40Z")

</div>

Do you mean that you only want the fields that you query as result ?

you can do that by :

```
{  
   "_source": "pistons",
   "query":{  
    "term":{"pistons":"metal"}
   }
  
}

```

This query will return only pistons which match with the value "metal" , it will not return the whole document .

---

<div class="post-metadata">

**Author:** ![shankarps](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shankarps/32/78663_2.png) [@shankarps](https://discuss.elastic.co/u/shankarps)\
**Post date:** [January 25, 2019, 6:30pm UTC](https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674/3 "2019-01-25T18:30:34Z")

</div>

@Tosh I want to search both fields. But I want to narrow the search based on he name of the field in the search query. So if the query says "10 pistons", it should effectively consider "\_source": "pistons", but if the query has "8 cylinders", it should search like this. "\_source": "pistons".

I can do this manually by changing the "\_source" based on the query, however I was looking for a built in approach.

---

<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:** [February 22, 2019, 6:44pm UTC](https://discuss.elastic.co/t/search-among-field-names-in-elasticsearch/165674/4 "2019-02-22T18:44:16Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
