# Index mapping problem

**URL:** <https://discuss.elastic.co/t/index-mapping-problem/365607>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [August 27, 2024, 10:14am UTC](https://discuss.elastic.co/t/index-mapping-problem/365607 "2024-08-27T10:14:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cazzz99](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@cazzz99](https://discuss.elastic.co/u/cazzz99)\
**Post date:** [August 27, 2024, 10:14am UTC](https://discuss.elastic.co/t/index-mapping-problem/365607/1 "2024-08-27T10:14:30Z")

</div>

My current mapping is like:

```auto
        self.es_client.indices.create(
            index=self.index_name,
            mappings={
                "properties":{
                    text_field: {"type": "text"},
                    dense_vector_field: {"type": "dense_vector"},
                    num_characters_field: {"type": "integer"}
                }
            }
        )

```

And it works well, however, when I try to add a property like:

```auto
        self.es_client.indices.create(
            index=self.index_name,
            mappings={
                "properties":{
                    text_field: {"type": "text"},
                    title_field: {"type": "text"},
                    dense_vector_field: {"type": "dense_vector"},
                    num_characters_field: {"type": "integer"}
                }
            }
        )

```

After the docs are indexed, the dense\_vector\_field turns to text type, thus I can not perform knn search, why is that?

the mappings after i add a new property on kibana:

```auto
{
  "mappings": {
    "properties": {
      "num_characters": {
        "type": "integer"
      },
      "output_dense_vector": {
        "type": "text"
      },
      "text": {
        "type": "text"
      },
      "title": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [August 27, 2024, 10:20am UTC](https://discuss.elastic.co/t/index-mapping-problem/365607/2 "2024-08-27T10:20:39Z")

</div>

> [@cazzz99](#):
>
> `output_dense_vector`

Are you sure the JSON doc you're sending is using the field name that you declared as dense\_vector?

Your mappings show a `output_dense_vector` field which you haven't declared in your mappings. Your mapping declares a `dense_vector_field` field.

Also elasticsearch should be declaring an array of floats above 100, so your field being declared as text is a little suspicious. Check to see the doc dense vector value you're inserting isn't quoted.

See docs [Dense vector field type | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/dense-vector.html)

---

<div class="post-metadata">

**Author:** ![cazzz99](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@cazzz99](https://discuss.elastic.co/u/cazzz99)\
**Post date:** [August 27, 2024, 10:46am UTC](https://discuss.elastic.co/t/index-mapping-problem/365607/3 "2024-08-27T10:46:46Z")

</div>

yep so its just a naming thing really, so my whole function is below:

```auto
    def create_index(self,text_field = "text",title_field = "title",dense_vector_field = "output_dense_vector",num_characters_field = "num_characters"):
        # es_client = connect_elasticsearch()
        self.es_client.indices.create(
            index=self.index_name,
            mappings={
                "properties":{
                    text_field: {"type": "text"},
                    title_field: {"type": "text"},
                    dense_vector_field: {"type": "dense_vector"},
                    num_characters_field: {"type": "integer"}
                }
            }
        )

```

also, my mapping on kibana BEFORE i added the title field is:

```auto
{
  "mappings": {
    "properties": {
      "num_characters": {
        "type": "integer"
      },
      "output_dense_vector": {
        "type": "dense_vector",
        "dims": 1024,
        "index": true,
        "similarity": "cosine"
      },
      "text": {
        "type": "text"
      }
    }
  }
}

```

so the embedding part should not be any problem, so , is there any other point I might missed? Thanks for the doc tho, but I've checked that already.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 27, 2024, 2:59pm UTC](https://discuss.elastic.co/t/index-mapping-problem/365607/4 "2024-08-27T14:59:47Z")

</div>

Some few things to check IMO:

- What is the response of `self.es_client.indices.create()` call?
- Do you delete the index BEFORE trying to recreate it?
- If not, you need to call the [PUT mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) instead
- Please note that the field names are not the same between BEFORE and what you are sending. Not sure if it's what you want or not.
