Skip to content

Commit

Permalink
Rename "exists" to "found" in TermVector and Get responses
Browse files Browse the repository at this point in the history
- Adds the "created" field to the index action response
- Reverses Delete class' notFound to Found to avoid double negative
  • Loading branch information
dakrone committed Jan 7, 2014
1 parent d23f640 commit 2cb40fc
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 92 deletions.
4 changes: 1 addition & 3 deletions docs/reference/search/termvectors.asciidoc
Expand Up @@ -170,7 +170,7 @@ Response:
"_index": "twitter",
"_type": "tweet",
"_version": 1,
"exists": true,
"found": true,
"term_vectors": {
"text": {
"field_statistics": {
Expand Down Expand Up @@ -222,5 +222,3 @@ Response:
}
}
--------------------------------------------------


5 changes: 2 additions & 3 deletions rest-api-spec/test/get/60_realtime_refresh.yaml
Expand Up @@ -28,7 +28,7 @@
id: 1
realtime: 1

- is_true: exists
- is_true: found

- do:
catch: missing
Expand All @@ -46,5 +46,4 @@
realtime: 0
refresh: 1

- is_true: exists

- is_true: found
8 changes: 4 additions & 4 deletions rest-api-spec/test/mget/10_basic.yaml
Expand Up @@ -23,22 +23,22 @@
- { _index: test_1, _type: test, _id: 2}
- { _index: test_1, _type: test, _id: 1}

- is_false: docs.0.exists
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }

- is_false: docs.1.exists
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: none }
- match: { docs.1._id: "1" }

- is_false: docs.2.exists
- is_false: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "2" }

- is_true: docs.3.exists
- is_true: docs.3.found
- match: { docs.3._index: test_1 }
- match: { docs.3._type: test }
- match: { docs.3._id: "1" }
Expand Down
8 changes: 4 additions & 4 deletions rest-api-spec/test/mget/11_default_index_type.yaml
Expand Up @@ -25,22 +25,22 @@
- { _id: 2}
- { _id: 1}

- is_false: docs.0.exists
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }

- is_false: docs.1.exists
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: none }
- match: { docs.1._id: "1" }

- is_false: docs.2.exists
- is_false: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "2" }

- is_true: docs.3.exists
- is_true: docs.3.found
- match: { docs.3._index: test_1 }
- match: { docs.3._type: test }
- match: { docs.3._id: "1" }
Expand Down
5 changes: 2 additions & 3 deletions rest-api-spec/test/mget/12_non_existent_index.yaml
Expand Up @@ -17,7 +17,7 @@
docs:
- { _index: test_2, _type: test, _id: 1}

- is_false: docs.0.exists
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
Expand All @@ -29,8 +29,7 @@
docs:
- { _index: test_1, _type: test, _id: 1}

- is_true: docs.0.exists
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }

3 changes: 1 addition & 2 deletions rest-api-spec/test/mget/13_missing_metadata.yaml
Expand Up @@ -43,10 +43,9 @@
docs:
- { _index: test_1, _id: 1}

- is_true: docs.0.exists
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}

9 changes: 4 additions & 5 deletions rest-api-spec/test/mget/15_ids.yaml
Expand Up @@ -25,14 +25,14 @@
body:
ids: [1, 2]

- is_true: docs.0.exists
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}

- is_false: docs.1.exists
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test }
- match: { docs.1._id: "2" }
Expand All @@ -43,14 +43,14 @@
body:
ids: [1, 2]

- is_true: docs.0.exists
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}

- is_true: docs.1.exists
- is_true: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test_2 }
- match: { docs.1._id: "2" }
Expand All @@ -70,4 +70,3 @@
mget:
index: test_1
body: {}

9 changes: 4 additions & 5 deletions rest-api-spec/test/mget/30_parent.yaml
Expand Up @@ -39,20 +39,19 @@
- { _id: 1, parent: 4, fields: [ _parent, _routing ] }
- { _id: 2, parent: 5, fields: [ _parent, _routing ] }

- is_false: docs.0.exists
- is_false: docs.1.exists
- is_false: docs.0.found
- is_false: docs.1.found

- is_true: docs.2.exists
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "1" }
- match: { docs.2.fields._parent: "4" }
- match: { docs.2.fields._routing: "4" }

- is_true: docs.3.exists
- is_true: docs.3.found
- match: { docs.3._index: test_1 }
- match: { docs.3._type: test }
- match: { docs.3._id: "2" }
- match: { docs.3.fields._parent: "5" }
- match: { docs.3.fields._routing: "5" }

6 changes: 3 additions & 3 deletions rest-api-spec/test/mget/40_routing.yaml
Expand Up @@ -22,10 +22,10 @@
- { _id: 1, routing: 4 }
- { _id: 1, routing: 5 }

- is_false: docs.0.exists
- is_false: docs.1.exists
- is_false: docs.0.found
- is_false: docs.1.found

- is_true: docs.2.exists
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "1" }
Expand Down
7 changes: 3 additions & 4 deletions rest-api-spec/test/mget/55_parent_with_routing.yaml
Expand Up @@ -32,13 +32,12 @@
- { _id: 1, parent: 4 }
- { _id: 1, parent: 4, routing: 5 }

- is_false: docs.0.exists
- is_false: docs.1.exists
- is_false: docs.0.found
- is_false: docs.1.found

- is_true: docs.2.exists
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "1" }
- match: { docs.2.fields._parent: "4" }
- match: { docs.2.fields._routing: "5" }

6 changes: 3 additions & 3 deletions rest-api-spec/test/mget/60_realtime_refresh.yaml
Expand Up @@ -29,7 +29,7 @@
body:
ids: [1]

- is_false: docs.0.exists
- is_false: docs.0.found

- do:
mget:
Expand All @@ -39,7 +39,7 @@
body:
ids: [1]

- is_true: docs.0.exists
- is_true: docs.0.found

- do:
mget:
Expand All @@ -50,4 +50,4 @@
body:
ids: [1]

- is_true: docs.0.exists
- is_true: docs.0.found
Expand Up @@ -422,7 +422,7 @@ private WriteResult shardDeleteOperation(DeleteRequest deleteRequest, IndexShard
indexShard.delete(delete);
// update the request with the version so it will go to the replicas
deleteRequest.version(delete.version());
DeleteResponse deleteResponse = new DeleteResponse(deleteRequest.index(), deleteRequest.type(), deleteRequest.id(), delete.version(), delete.notFound());
DeleteResponse deleteResponse = new DeleteResponse(deleteRequest.index(), deleteRequest.type(), deleteRequest.id(), delete.version(), delete.found());
return new WriteResult(deleteResponse, deleteRequest.version(), null, null);
}

Expand Down
Expand Up @@ -37,18 +37,18 @@ public class DeleteResponse extends ActionResponse {
private String id;
private String type;
private long version;
private boolean notFound;
private boolean found;

public DeleteResponse() {

}

public DeleteResponse(String index, String type, String id, long version, boolean notFound) {
public DeleteResponse(String index, String type, String id, long version, boolean found) {
this.index = index;
this.id = id;
this.type = type;
this.version = version;
this.notFound = notFound;
this.found = found;
}

/**
Expand Down Expand Up @@ -82,8 +82,8 @@ public long getVersion() {
/**
* Returns <tt>true</tt> if there was no doc found to delete.

This comment has been minimized.

Copy link
@benatwork99

benatwork99 Jan 30, 2014

Should this be changed to reflect notFound > found change?

This comment has been minimized.

Copy link
@dakrone

dakrone Jan 30, 2014

Author Member

Yes, it should, I'll fix this.

*/
public boolean isNotFound() {
return notFound;
public boolean isFound() {
return found;
}

@Override
Expand All @@ -93,7 +93,7 @@ public void readFrom(StreamInput in) throws IOException {
type = in.readSharedString();
id = in.readString();
version = in.readLong();
notFound = in.readBoolean();
found = in.readBoolean();
}

@Override
Expand All @@ -103,6 +103,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeSharedString(type);
out.writeString(id);
out.writeLong(version);
out.writeBoolean(notFound);
out.writeBoolean(found);
}
}
Expand Up @@ -114,13 +114,13 @@ public void onResponse(IndexDeleteResponse indexDeleteResponse) {
long version = Versions.MATCH_ANY;
boolean found = false;
for (ShardDeleteResponse deleteResponse : indexDeleteResponse.getResponses()) {
if (!deleteResponse.isNotFound()) {
if (deleteResponse.isFound()) {
version = deleteResponse.getVersion();
found = true;
break;
}
}
listener.onResponse(new DeleteResponse(request.index(), request.type(), request.id(), version, !found));
listener.onResponse(new DeleteResponse(request.index(), request.type(), request.id(), version, found));
}

@Override
Expand Down Expand Up @@ -193,7 +193,7 @@ protected PrimaryResponse<DeleteResponse, DeleteRequest> shardOperationOnPrimary
}
}

DeleteResponse response = new DeleteResponse(request.index(), request.type(), request.id(), delete.version(), delete.notFound());
DeleteResponse response = new DeleteResponse(request.index(), request.type(), request.id(), delete.version(), delete.found());
return new PrimaryResponse<DeleteResponse, DeleteRequest>(shardRequest.request, response, null);
}

Expand Down
Expand Up @@ -31,35 +31,35 @@
public class ShardDeleteResponse extends ActionResponse {

private long version;
private boolean notFound;
private boolean found;

public ShardDeleteResponse() {
}

public ShardDeleteResponse(long version, boolean notFound) {
public ShardDeleteResponse(long version, boolean found) {
this.version = version;
this.notFound = notFound;
this.found = found;
}

public long getVersion() {
return version;
}

public boolean isNotFound() {
return notFound;
public boolean isFound() {
return found;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
version = in.readLong();
notFound = in.readBoolean();
found = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(version);
out.writeBoolean(notFound);
out.writeBoolean(found);
}
}
Expand Up @@ -107,7 +107,7 @@ protected PrimaryResponse<ShardDeleteResponse, ShardDeleteRequest> shardOperatio
}


ShardDeleteResponse response = new ShardDeleteResponse(delete.version(), delete.notFound());
ShardDeleteResponse response = new ShardDeleteResponse(delete.version(), delete.found());
return new PrimaryResponse<ShardDeleteResponse, ShardDeleteRequest>(shardRequest.request, response, null);
}

Expand Down
Expand Up @@ -68,7 +68,7 @@ private static class FieldStrings {
public static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
public static final XContentBuilderString _ID = new XContentBuilderString("_id");
public static final XContentBuilderString _VERSION = new XContentBuilderString("_version");
public static final XContentBuilderString EXISTS = new XContentBuilderString("exists");
public static final XContentBuilderString FOUND = new XContentBuilderString("found");
public static final XContentBuilderString TERMS = new XContentBuilderString("terms");
public static final XContentBuilderString TERM_VECTORS = new XContentBuilderString("term_vectors");

Expand Down Expand Up @@ -169,7 +169,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(FieldStrings._TYPE, type);
builder.field(FieldStrings._ID, id);
builder.field(FieldStrings._VERSION, docVersion);
builder.field(FieldStrings.EXISTS, isExists());
builder.field(FieldStrings.FOUND, isExists());
if (!isExists()) {
builder.endObject();
return builder;
Expand Down

0 comments on commit 2cb40fc

Please sign in to comment.