@@ -81,11 +81,19 @@ public function orWhereNotExact($column, $value, $options = []): self
8181 }
8282
8383 // ----------------------------------------------------------------------
84- // Term Exists Query - check if a field has an indexed value
84+ // Exists Query - check if a field has an indexed value
8585 // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
86+ //
87+ // Named whereFieldExists (not whereExists) to avoid colliding with
88+ // Laravel's base Builder::whereExists(Closure $callback) — the SQL
89+ // EXISTS subquery clause, which has entirely different semantics.
90+ //
91+ // Works on top-level fields and on nested-mapped fields: the compiler
92+ // auto-wraps the exists clause in a nested query when the field's path
93+ // is mapped as nested.
8694 // ----------------------------------------------------------------------
8795
88- public function whereTermExists ($ column , $ boolean = 'and ' , $ not = false ): self
96+ public function whereFieldExists ($ column , $ boolean = 'and ' , $ not = false ): self
8997 {
9098 $ this ->wheres [] = [
9199 'type ' => 'Basic ' ,
@@ -99,19 +107,52 @@ public function whereTermExists($column, $boolean = 'and', $not = false): self
99107 return $ this ;
100108 }
101109
102- public function whereNotTermExists ($ column )
110+ public function whereFieldDoesntExist ($ column ): self
111+ {
112+ return $ this ->whereFieldExists ($ column , 'and ' , true );
113+ }
114+
115+ public function orWhereFieldExists ($ column ): self
116+ {
117+ return $ this ->whereFieldExists ($ column , 'or ' , false );
118+ }
119+
120+ public function orWhereFieldDoesntExist ($ column ): self
121+ {
122+ return $ this ->whereFieldExists ($ column , 'or ' , true );
123+ }
124+
125+ /**
126+ * @deprecated Use whereFieldExists() instead. Will be removed in v6.
127+ */
128+ public function whereTermExists ($ column , $ boolean = 'and ' , $ not = false ): self
129+ {
130+ return $ this ->whereFieldExists ($ column , $ boolean , $ not );
131+ }
132+
133+ /**
134+ * @deprecated Use whereFieldDoesntExist() instead. Will be removed in v6.
135+ */
136+ public function whereNotTermExists ($ column ): self
103137 {
104- return $ this ->whereTermExists ($ column , 'and ' , true );
138+ return $ this ->whereFieldExists ($ column , 'and ' , true );
105139 }
106140
107- public function orWhereTermExists ($ column )
141+ /**
142+ * @deprecated Use orWhereFieldExists() instead. Will be removed in v6.
143+ */
144+ public function orWhereTermExists ($ column ): self
108145 {
109- return $ this ->whereTermExists ($ column , 'or ' , false );
146+ return $ this ->whereFieldExists ($ column , 'or ' , false );
110147 }
111148
112- public function orWhereNotTermsExists ($ column )
149+ /**
150+ * @deprecated Use orWhereFieldDoesntExist() instead. Will be removed in v6.
151+ * Note: the original method name had a typo ("Terms" plural).
152+ */
153+ public function orWhereNotTermsExists ($ column ): self
113154 {
114- return $ this ->whereTermExists ($ column , 'or ' , true );
155+ return $ this ->whereFieldExists ($ column , 'or ' , true );
115156 }
116157
117158 // ----------------------------------------------------------------------
0 commit comments