[failed to parse search source. unknown search element [mappings]]

Hi,

I am trying to exclude a field from _source and I am trying to run this curl command -

curl -X POST "http://localhost:9200/appindex/appindex/_search" -d '{
  "mappings":{
     "appindex":{
        "_source":{
           "excludes":[
              "field_attachment_resource_name_base64"
           ]
        },
        "properties":{
           "field_attachment_resource_name_base64":{
              "type":"attachment",
              "fields":{
                 "content":{
                    "type":"string",
                    "store":true
                 }
              }
           },
           "name":{
              "type":"string"
           }
        }
     }
  }
}'

And this is the error I get -

SearchParseException[failed to parse search source. unknown search element [mappings]]

{"error":{"root_cause":[{"type":"search_parse_exception","reason":"failed to parse search source. unknown search element [mappings]","line":2,"col":14}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"pbaindex","node":"PQBFXvM5XniVQ","reason":{"type":"search_parse_exception","reason":"failed to parse search source. unknown search element [mappings]","line":2,"col":14}}]},"status":400}

Your url looks like a search command. The request body looks like put mapping command. Not sure if you want to exclude field during indexing or during searching.

Thanks for your response! I added new type "attachment" using mapper attachment plugin (ES 2.4).

I have indexed two documents and the base64 "content" field is showing up under "_source" which increases the size of the document.

I would like to exclude it from _source. Please advise best approach.

I was following this url - https://qbox.io/blog/index-attachments-files-elasticsearch-mapper

it should be

curl -X POST "http://localhost:9200/appindex" -d '{
  "mappings":{
....

instead of

curl -X POST "http://localhost:9200/appindex/appindex/_search" -d '{
  "mappings":{
....

Thank you! I get this new error now -

{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"appindex"}],"type":"index_already_exists_exception","reason":"already exists","index":"appindex"},"status":400}

This is my new curl command -

curl -X POST "http://localhost:9200/appindex" -d '{
  "mappings":{
     "appindex":{
        "_source":{
           "excludes":[
              "field_attachment_resource_name_base64"
           ]
        },
        "properties":{
           "field_attachment_resource_name_base64":{
              "type":"attachment",
              "fields":{
                 "content":{
                    "type":"string",
                    "store":true
                 }
              }
           },
           "name":{
              "type":"string"
           }
        }
     }
  }
}'

Yes, you need to recreate your index.

Delete index first with

curl -X DELETE "http://localhost:9200/appindex"

Then execute the command that you posted.

Please, note that it will delete all data in this index. So, you will have to add all your data again.

Okay. I will try that. Thanks!

It worked!!! Thank you very much!!!!!

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