Im having problems getting a query to return the results i require. Im wanting to search for all documents which have a Field name called 'Title' but only them where the value is null.
By default Elasticsearch does not store fields with null value in its index, so you are not able to distinguish documents without Title field at all from documents where this field contains null. To cope with this issue you have explicitly choose some value that will indicate that field is empty. Look at this article for details.
Related
I wonder how do I filter documents in elastic search that doesn't have particular field or have this field with particular value.
example, I have a doc which may have the field "only2".
and I query for all the docs, that have this field equals to my username and the whole the docs that are not set to my username (meaning I set it to be public)
I have a type with a field indicating if to reveal another field. For example, for a document, if ifRevealAge is true, value of the age field should be retrieved from _source and included in query result for the document. If ifRevealAge is false, then age field should not be included in the query result for the document. Is it possible by query API?
If it is not, how to do it through java API? I think the method toXContent(XContentBuilder builder, ToXContent.Params params) of GetResponse is supposed to do so but I can't find any documentation or references for how to use the method for filtering / modifying response result conditionally. The api documentation is just too concise.
Many thanks
So basically I have an index that I created, and have set the mapping so that whenever a document is created, the _id of the document is set as one of the fields of the document.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html
This was easy enough, but I noticed that when I update that field (through the Java API), the _id of the document remains the same so the field and _id are out of sync.
Is this intended behaviour? If so, does anyone know why, and if it is a bad idea to set the _id as a field that may frequently change?
If I wanted the _id and the field to be in sync, is reindexing an option?
Thanks
The _id is extracted and copied from that field while indexing.
Also _id is used as routing key and it decides where the document should go in the whole cluster.
Hence its not possible to keep _id as reference to some field , rather that valued is copied to _id before indexing.
If you want to change _id , re-indexing is the only option.
I have a document whose structure changes often, how can I index nested documents inside it without changing the mapping on ElasticSearch?
You can index documents in Elasticsearch without providing a mapping yes.
However, Elasticsearch makes a decision about the type of a field when the first document contains a value for that field. If you add document 1 and it has a field called item_code, and in document 1 item_code is a string, Elasticsearch will set the type of field "item_code" to be string. If document 2 has an integer value in item_code Elasticsearch will have already set the type as string.
Basically, field type is index dependant, not document dependant.
This is mainly because of Apache Lucene and the way it handles this information.
If you're having a case where some data structure changes, while other doesn't, you could use an object type, http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-object-type.html.
You can even go as far as to use "enabled": false on it, which makes elasticsearch just store the data. You couldn't search it anymore, but maybe you actually don't even want that?
In the documentation, some types, such as numbers and dates, it specifies that store defaults to no. But that the field can still be retrieved from the json.
Its confusing. Does this mean _source?
Is there a way to not store a field at all, and just have it indexed and searchable?
None of the field types are stored by default. Only the _source field is. That means you can always get back what you sent to the search engine. Even if you ask for specific fields, elasticsearch is going to parse the _source field for you and give you back those fields.
You can disable the _source if you want but then you could only retrieve the fields that you explicitly stored, according to your mapping.