Last active
August 29, 2015 13:59
-
-
Save cjbottaro/10920007 to your computer and use it in GitHub Desktop.
duplicate percolator results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "elasticsearch" | |
client = Elasticsearch::Client.new | |
if !client.indices.exists(index: "percolator_test") | |
client.indices.create index: "percolator_test" | |
end | |
client.indices.put_mapping index: "percolator_test", | |
type: "type1", | |
body: { | |
type1: { | |
properties: { | |
field1: { type: "integer" }, | |
field2: { type: "integer" }, | |
field3: { type: "integer" } | |
} | |
} | |
} | |
client.index index: "percolator_test", | |
type: ".percolator", | |
id: "query1", | |
body: { | |
query: { | |
filtered: { | |
query: { match_all: {} }, | |
filter: { | |
and: [ | |
{ term: { field1: 1 } }, | |
{ term: { field2: 2 } } | |
] | |
} | |
} | |
}, | |
attribute1: 123, | |
attribute2: 456 | |
} | |
# Uncommenting this line fixes the problem. | |
# client.indices.refresh index: "percolator_test" | |
# Exactly the same as the above `query1` percolator query. | |
client.index index: "percolator_test", | |
type: ".percolator", | |
id: "query1", | |
body: { | |
query: { | |
filtered: { | |
query: { match_all: {} }, | |
filter: { | |
and: [ | |
{ term: { field1: 1 } }, | |
{ term: { field2: 2 } } | |
] | |
} | |
} | |
}, | |
attribute1: 123, | |
attribute2: 456 | |
} | |
client.index index: "percolator_test", | |
type: ".percolator", | |
id: "query2", | |
body: { | |
query: { | |
filtered: { | |
query: { match_all: {} }, | |
filter: { | |
and: [ | |
{ term: { field3: 3 } }, | |
] | |
} | |
} | |
}, | |
attribute1: 123, | |
attribute2: 789 | |
} | |
client.indices.refresh index: "percolator_test" | |
response = client.get index: "percolator_test", type: ".percolator", id: "query1" | |
response = client.percolate index: "percolator_test", | |
type: "type1", | |
body: { | |
doc: { | |
field1: 1, | |
field2: 2, | |
field3: 3 | |
}, | |
filter: { | |
and: [ | |
{ term: { attribute1: 123 } }, | |
{ term: { attribute2: 456 } } | |
] | |
} | |
} | |
puts response["matches"].inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment