# How to index some fields of an object

**URL:** <https://discuss.elastic.co/t/how-to-index-some-fields-of-an-object/221081>\
**Category:** Elasticsearch\
**Created:** [February 26, 2020, 5:16pm UTC](https://discuss.elastic.co/t/how-to-index-some-fields-of-an-object/221081 "2020-02-26T17:16:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eomm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eomm/32/63362_2.png) [@Eomm](https://discuss.elastic.co/u/Eomm)\
**Post date:** [February 26, 2020, 5:16pm UTC](https://discuss.elastic.co/t/how-to-index-some-fields-of-an-object/221081/1 "2020-02-26T17:16:06Z")

</div>

Hello,  
I have to log a dynamic object, but I'm interested only to index some fields (not all), but when I configure this behaviour I can't search for those fields

Here an example of what I'm doing:

```
curl --request PUT 'http://localhost:9200/manuel-prova?pretty' \
--header 'Content-Type: application/json' \
--data-raw '{
  "mappings": {
    "log": {
      "properties": {
        "hello": {
          "type": "object",
          "enabled": false,
          "properties": {
            "my-api-key": {
              "type": "text"
            }
          }
        },
        "check": {
          "type": "boolean"
        }
      }
    }
  }
}'

```

Then I insert the data:

```
curl --request POST 'http://localhost:9200/manuel-prova/log?pretty' \
--header 'Content-Type: application/json' \
--data-raw '{
  "hello": {
  	"foo": "bar",
  	"my-api-key": "QWERTY"
  },
  "check": true
}'

```

Finally, I tried to query:

```
curl --request POST 'http://localhost:9200/manuel-prova/_search?pretty' \
--header 'Content-Type: application/json' \
--data-raw '{
  "query": {
    "bool": {
      "must": [
        { "exists": { "field": "hello.my-api-key" } }
      ]
    }
  }
}'

```

This query doesn't work.

If I change to `{ "exists": { "field": "check" } }` for example, it works.

Do you have any suggestion?  
Thank you very much

---

<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:** [March 25, 2020, 5:16pm UTC](https://discuss.elastic.co/t/how-to-index-some-fields-of-an-object/221081/2 "2020-03-25T17:16:11Z")

</div>

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