I use Elastic to host an index used for managing list filters, which returns IDs matching a query, that I then use in Seek call on a SQL database to retrieve large sets of data with decent efficiency. Lately I've seen a really strange issue in Elastic where my queries are returning documents that do not match the query even though I'm not using any fuzzy settings or text analyzers.
We use the PHP client so my code below is formatted in that manner. I'm trying to retrieve only document IDs where the field "status = 0", but very often I get back documents where the status is some other arbitrary integer. The point is that the query should be returning an exact match. I've tried several different approaches including a "Term" query inside a Boolean, a match query outside a Boolean, and a filter inside a Boolean. All for "status=0" and still I get back the exact same documents that don't match, mixed in with documents that meet the query params.
$params = [
'size' => 100,
'index' => $index,
'body' => [
'query' => [
'bool' => [
'filter' => [
'term' => [
'status' => 0
]
],
'must' => [
[
'terms' => [
'job_number' => $job_numbers
],
],
[
'range' => [
$range_column => [
'gte' => $start_date,
'lte' => $end_date
]
]
]
],
'must_not' => [
[
'exists' => [
'field' => 'deleted'
]
]
]
],
],
'sort' => [
$sort_column => [
'order' => $direction,
'mode' => 'avg',
],
],
]
];
Any ideas on why this could be happening? This is occurring on even a really basic setup with 1 node, 1 shard, and pretty much default configs.
The "status" field is mapped to be a "number" so matching should be exact, but it's obviously not.
I've tried deleting and rebuilding the index from scratch, and I've tried delete_by_query to drop all data in the index and rebuild. In Kibana, the docs do not return if I use KQL to find "status=0", but for some reason through the Elastic API they continue to return as false matches.
Additionally, to add to the weirdness, I get back 88 documents even though the batch size is 100 and a count aggregation shows that there are over 1500 matching docs.
Any help, thoughts, tips, questions to help me help you help me? This has been a thorn in my side for about a week now.