Filtering fails with 400 Bad Request when values are associative arrays
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3585940. --> Reported by: [nnevill](https://www.drupal.org/user/835208) Related to !27 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When using the Pinecone VDB provider with Search API filters (e.g., excluding certain content types in a View), the Pinecone API returns a 403/400 Bad Request.</p> <p>The error message received is:<br> <code>"the $nin operator must be followed by a list of strings or a list of numbers, got {...} instead"</code></p> <h3 id="summary-steps-reproduce">Steps to reproduce</h3> <ol> <li>Setup a Search API index using Pinecone as the backend.</li> <li>Create a View and add a filter that uses a "Not In" or "Is not one of" operator (such as excluding specific Content Types).</li> <li>Execute the search.</li> <li>Observe the Bad Request (400) error from Pinecone.</li> </ol> <h3 id="summary-proposed-resolution">Technical Cause</h3> <p>In PineconeProvider::processConditionGroup(), the values for filters are retrieved directly from the condition object. Drupal often provides these as associative arrays where the keys are machine names (e.g., ['article' =&gt; 'article']).</p> <p>When these are sent to the Pinecone API, PHP's json_encode converts associative arrays into JSON Objects ({}), but the Pinecone API strictly requires a JSON Array ([]) for operators like $nin and $in. Additionally, single-value operators like $eq or $ne fail because they attempt to access index [0], which does not exist in a string-keyed associative array.</p> <h3 id="summary-problem-motivation">Proposed Resolution</h3> <p>Normalize the filter values using array_values() within processConditionGroup() to ensure that string keys are stripped and the resulting JSON is a proper indexed list.</p> <h3 id="summary-problem-motivation">Code change</h3> <p>Replace this:</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br>$values </span><span style="color: #007700">= </span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">()) ? </span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">() : [</span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">()];<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>with:</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #FF8000">// Use array_values() to strip string keys (e.g. "topic" =&gt; "topic") <br>// and ensure we pass a flat indexed list to Pinecone.<br></span><span style="color: #0000BB">$values </span><span style="color: #007700">= </span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">()) ? </span><span style="color: #0000BB">array_values</span><span style="color: #007700">(</span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">()) : [</span><span style="color: #0000BB">$condition</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">()];<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div>
issue