I am using TCP client to perform delete operation.
sample code:
DeleteRequestBuilder builder = client.prepareDelete(indexName, indexType,indexDocumentId);
ListenableActionFuture<DeleteResponse> deleteResponse = builder.setOperationThreaded(false).execute();
deleteResponse.actionGet(ESTemplateHelper.INDEX_STATE_ACK_TIMEOUT);
deleteStatus = deleteResponse.isDone();
I am passing empty value/"" to indexDocumentId.
deleteStatus is always true for empty documentId. But document is not deleted. am i missing something? Isn't it expected to throw any error?
The prepareDelete command is for deleting a single document by its ID. For more information: https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/delete.html
Now, the ID of a document cannot be empty string. So, there should be no such document. The reason deleteStatus is true because it holds the value "whether the request is done or not?" and not "was the document deleted?". If you drill down the response, I believe you will find: found = false.
In case, you are passing an empty string in the hope of deleting all the documents of type indexType in the index indexName, then prepareDelete is not the right API for that.
Maybe, you can execute a query on all documents in your type, and delete them one by one. There is also delete by query API but it has been deprecated in 1.5 and removed in 2.0 because it can potentially cause OOM errors. More details here: https://www.elastic.co/guide/en/elasticsearch/reference/1.6/docs-delete-by-query.html
In case, you don't care about this index altogether, then deleting the index is the quickest and cleanest way to go: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-delete-index.html. I believe in the similar fashion you can delete your type too.
Eg: curl -XDELETE http://localhost:9200/indexName/indexType
Related
I am trying to run the below code in Python using Elasticsearch Ver 7.1, however the following errors come up:
ElasticsearchDeprecationWarning: [types removal] Using include_type_name in put mapping requests is deprecated. The parameter will be removed in the next major version.
client.indices.put_mapping(index=indexName,doc_type='diseases', body=diseaseMapping, include_type_name=True)
followed by:
ElasticsearchDeprecationWarning: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
client.index(index=indexName,doc_type=docType, body={"name": disease,"title":currentPage.title,"fulltext":currentPage.content})
How I am supposed to amend my code to make it (see here) work in line with Elasticsearch 7X version? Any kind of help would be much appreciated.
This is just a warning right now, but it will become an error in Elasticsearch 8.
From last few version, Elasticsearch has been planning the removal of index types inside an index
ES5 - Setting index.mapping.single_type: true on an index will enable the single-type-per-index behavior which will be enforced in 6.0.
In ES6 - you can't have more than 1 index type inside 1 index
In ES7 - the concept of types inside an index has been deprecated
In ES8 - it will be removed, and you can't use types for query or while inserting documents
My suggestion would be to design an application and mapping in such a way that it doesn't include type parameter in index
To know the reason why elastic search has done this here is a link: https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_why_are_mapping_types_being_removed
A common issue (and difficult to spot) for this error message could be misspelling the endpoint, e.g.:
Misspelled:
/search
Correct:
/_search
Double check if your endpoint is correct as ElasticSearch may think you are trying to manipulate (add, update, remove) a document and you are giving a type, which is not the case (you are trying to call an endpoint).
I'm trying to get a list of Terms from a termvectorresponse in an elasticsearch plugin. I want to get access to all of the statistics which are tied to the terms and am having trouble figuring out how to do that.
After making a TermVectorsRequest...
TermVectorsRequest tvReq = new TermVectorsRequest(request.param("index"), request.param("type"), request.param("id"));
tvReq.termStatistics(true);
tvReq.selectedFields(request.param("field"));
and getting a response from the client...
TermVectorsResponse tvResponse = client.termVectors(tvReq).get();
I can get access to the id, index, etc. In the fields I get "contents" which is the field name that I want. From there though it looks like I can run...
tvResponse.getFields().terms("some term here")
in which the Terms object this returns has access to the stats I want.
I have a few issues with this though. One is that only "contents" seems to be non null. In the termvectors endpoint in elastic I get several different terms of which I've tried plugging into here. Two, is I want to get a list of terms rather than having to type in which term I want.
How can I go about doing this?
Thanks
Figured it out. Theres an interator on terms you can use. on .terms you have to pass it the field and you'll get the Terms object back. From that you can use the .iterator to get each individual term and do whatever you want with them.
Using the fake index per user as suggested by docs. ES version 1.6.0 sometimes fails to behave as expected.
Checking the alias:
curl localhost:9200/testbig/_alias/<userId>
{"<indexname>":{"aliases":{"<userId>":{"filter":{"term":
{"userId":"<userId>"}},"index_routing":"<userId>","search_routing":"<userId>"}}
}}
But trying to update a document:
curl -XPOST localhost:9200/<userId>/<type>/<id>/_update -d
'{"doc":{"userId":"<userId>","field1":"val1"}}'
I get
{ "error": "ElasticsearchIllegalArgumentException[Alias [<userId>] has
index routing associated with it [<userId>], and was provided with
routing value [<DIFFERENTuserId>], rejecting operation]",
"status": 400 }
In case anyone else suffers a similar issue, what causes is this:
If you start by using actual separate indexes for each user, it's OK to have records with the same id, i.e. paths like
localhost:9200/userid1/type/id1
localhost:9200/userid2/type/id1
but when the userids are just aliases, these correspond, of course, to the same document. Hence the routing clash on subsequent updates.
version: 1.15.2
r.db('test')
.table('form')
.filter(r.row('yyy').eq('aaa').or(r.row('id').eq('aaa')))
.limit(10)
Why this query cannot match a document where id is aaa but without field yyy
There is special handling for non-existing fields (default: false) so I guess it is best to rewrite the query to not call .eq() on a missing field. You could either check id first:
.filter(r.row('id').eq('aaa').or(r.row('yyy').eq('aaa')))
or maybe by setting the default behavior directly on the operation with missing fields:
.filter(r.row('yyy').eq('aaa').default(false).or(r.row('id').eq('aaa')))
BTW: an update to this answer. After reporting a documentation bug for RethinkDB it turns out, this is already mentioned in a troubleshooting guide: http://www.rethinkdb.com/docs/troubleshooting/#filters-with-or-return-incorrect/unexpected-r
I create a new profile document with the following code:
Set doc = db.Createdocument()
doc.Form = "SMBPrivateProfile"
Call doc.Computewithform(True,True)
Call doc.Save(True, False)
But whenever I want to read a field by #GetProfileField i get an empty string, even if the field I want to read has a default value.
After opening & saving the document manually everything works.
Further details:
I improved an application and hit Application --> Replace Design.... The new version includes a new field within the profile document. When reading one of these new fields, the result is an empty string. When reading an 'old' field within the same document the result is the expected string.
e.g.:
MessageBox([OK];"Title"; #GetProfileField("SMBPrivateProfile"; "OLD_FIELD"; #ThisName))
--> Will result in: "This is a fancy old default value"
MessageBox([OK];"Title"; #GetProfileField("SMBPrivateProfile"; "NEW_FIELD"; #ThisName))
--> Will result in: "" (instead of "This is a fancy new default value")
That's not a profile document. To create profile document use:
db.GetProfileDocument("SMBPrivateProfile");
You can also add a second parameter for a unique key in addition to profile name.
Also consider if you really want to use profile documents. They are heavily cached and not visible in any views.
If I'm reading you right, it appears that you have updated a form and added a new field with a default value formula. You are then reading an existing document. When you do this, the new field that you added to the form does not yet exist. New fields and formulas aren't applied to existing documents until you do something to force them to be applied.
If it's a regular document (as your original code indicated), you can just open the document in the Notes client, edit, and re-save it. That will create the NEW_FIELD and give it its value. If there are lots of these documents, you could write a simple formula agent to do this via #Command([ToolsRefreshAllDocs]) or #Command( [ToolsRefreshSelectedDocs]).
If it is a profile document (as per the responce chain to #Panu's anser), then after you do the replace design you will have to write an agent to open the existing profile document using db.getProfileDocument use doc.ReplaceItemValue("NEW_FIELD";"new value").