Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeleteByQuery delete all items in index #18

Closed
y-vasilyev opened this issue Feb 17, 2012 · 3 comments
Closed

DeleteByQuery delete all items in index #18

y-vasilyev opened this issue Feb 17, 2012 · 3 comments

Comments

@y-vasilyev
Copy link

Following code delete all records in index, not only with id = "1404.0.0"

        var indexedData = new[] { "1404.0.0" };

        string query = @" { ""query"" : {
                        ""terms"" : { ""id"" : [" + string.Join(",", indexedData.Select(x => @"""" + x + @"""")) + @"] }
                } }";

       var status = client.DeleteByQuery<AddressSearch>(query);

I captured following request

DELETE http://10.54.xx.xx:9200/test_create/address_search/?pretty=true
HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: 10.54.18.47:9200
Content-Length: 64
Expect: 100-continue
Connection: Keep-Alive

{ "query" : {
"terms" : { "id" : ["1404.0.0"] }
} }

On elastic search forum I got answer that
I should replace :
http://10.54.xx.xx:9200/test_create/address_search/?pretty=true
by : http://10.54.xx.xx:9200/test_create/address_search/_query?pretty=true

More info here
https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/zdKU9BiUwj0

Thanks!

@y-vasilyev
Copy link
Author

Correct query is
{
"terms" : { "id" : ["1404.0.0"] }
}

I fixed delete function, now it's work fine

public ConnectionStatus DeleteByQuery(string query, DeleteByQueryParameters parameters) where T : class
{
query.ThrowIfNullOrEmpty("query");
var index = this.Settings.DefaultIndex;
index.ThrowIfNullOrEmpty("Cannot infer default index for current connection.");

        var typeName = this.InferTypeName<T>();
                   var path = this.CreatePath(index, typeName, "_query"); // ADDED _query
        if (parameters != null && !parameters.Equals(default(DeleteByQueryParameters)))
            path = this.AppendDeleteByQueryParametersToPath(path, parameters);
        return this._deleteToPath(path, query);
    }

@Mpdreamz
Copy link
Member

Yikes thats a pretty nasty regression. I noticed all delete by query tests issue a match_all {} which makes it pretty hard to differentiate between a successful DELETE BY QUERY and a DELETE MAPPING

I've updated the tests and fixed the various delete by query calls. Can you confirm the latest commit fixed this for you ?

Thanks for reporting !

@y-vasilyev
Copy link
Author

I just tested your last commit - it works fine, thank you for fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants