1

I added an extra field called "title" with the Put Mapping API and then tried a normal search on my index with GET index_name/type/_search but the records don't show any field with "title" in it. Is it because the field has no content in it? If so how do I get fields with no content?

Thank you.

1 Answer 1

1

if you have _source enabled, elasticsearch will return the field value(whether empty or not), which you sent to it. as shown in below example.

{
  "title" : "" // see empty value
}

And GET API on this doc-id returns below response

{
    "_index": "newso",
    "_type": "_doc",
    "_id": "1",
    "_version": 2,
    "_seq_no": 1,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "" // same value is returned in response.
    }
}

EDIT:- Based on @Val comment, If you are looking to find this newly added title field in old documents, where you didn't index this field, you will not be able to find it, As elasticsearch is schema-less, and doesn't enforce that you have to mandatory index a field. Also you can add/remove fields without updating mapping as its schemaless.

For this matter, even if you index a new document, after adding this title field in mapping, and don't include title field, then for that document again title field will not be returned.

Sign up to request clarification or add additional context in comments.

9 Comments

I think the OP expects to find the title field in all existing documents, even though it is not present in the source. You should just mention that the source is never modified by ES and will show whatever has been sent, not more, not less
@Val, I see updating the answer.
@ElasticsearchNinja yes I have _source enabled but the title field doesn't show up. Also I already have 100 documents indexed and after that I added the title field.
@GowthamMunukutla adding a new title field in the mapping will not add that field to all existing document sources. You need to reindex your documents with an empty title field if you want to see that field in your source.
Worth noting that update by query would also have worked without having to reindex all the documents.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.