
    ci{                        d dl Zd dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZmZm Z  dd	l!m"Z"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z) erddl*m+Z+m,Z,  G d de          Z- ede-          Z. G d dee.                   Z/ G d dee.                   Z0 G d dee%         e(          Z1 G d dee%                   Z2 G d de2e%                   Z3 G d de2e%                   Z4dS )    N)TYPE_CHECKINGAnyCallableDictGenericIteratorListOptionalProtocolTupleTypeUnioncastoverload)SelfTypeVar   )AAggAggBase)InstrumentedField)IllegalOperation)BoolQQuery)HitResponse)_RAnyUsingTypeAttrDictDslBaserecursive_to_dict)FieldObjectc                       e Zd ZdefdZdS )SupportsClonereturnc                     d S N selfs    ]/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/elasticsearch/dsl/search_base.py_clonezSupportsClone._clone3             N)__name__
__module____qualname__r   r.   r*   r0   r-   r&   r&   2   s!        !!!!!!!r0   r&   _S)boundc                        e Zd ZdZdedefdZdefdZeZ	de
de
defd	Zdede
fd
Zdede
ddf fdZdeeee         ef         fdZdeeee         ef         ddfdZ xZS )
QueryProxyz
    Simple proxy around DSL objects (queries) that can be called
    (to add query/post_filter) and also allows attribute access which is proxied to
    the wrapped query.
    search	attr_namec                 0    || _         d | _        || _        d S r)   _search_proxied
_attr_name)r,   r8   r9   s      r-   __init__zQueryProxy.__init__@   s    )-#r0   r'   c                     | j         d uS r)   )r=   r+   s    r-   __nonzero__zQueryProxy.__nonzero__E   s    }D((r0   argskwargsc                     | j                                         }t          || j                  }|j        t          |i ||_        n|xj        t          |i |z  c_        |S r)   )r<   r.   getattrr>   r=   r   )r,   rB   rC   sproxieds        r-   __call__zQueryProxy.__call__J   sq    L!! !T_--# $1&11G4 26 2 22 r0   c                 ,    t          | j        |          S r)   )rE   r=   )r,   r9   s     r-   __getattr__zQueryProxy.__getattr__X   s    t}i000r0   valueNc                    |                     d          sH| j        At          | j                                                  | _        t	          | j        ||           t                                          ||           d S )N_)
startswithr=   r   to_dictsetattrsuper__setattr__)r,   r9   rK   	__class__s      r-   rR   zQueryProxy.__setattr__[   sr    ##C(( 	9}( !$-"7"7"9"9 : :y%888Iu-----r0   c                 *    | j         | j        | j        fS r)   r;   r+   s    r-   __getstate__zQueryProxy.__getstate__b   s    |T]DO;;r0   statec                 0    |\  | _         | _        | _        d S r)   r;   )r,   rV   s     r-   __setstate__zQueryProxy.__setstate__e   s    7<4dmT___r0   )r1   r2   r3   __doc__r4   strr?   boolrA   __bool__r   rH   rJ   rR   r   r
   r   rU   rX   __classcell__rS   s   @r-   r7   r7   9   sH        $r $c $ $ $ $
)T ) ) ) ) Hc S R    1S 1S 1 1 1 1.S . . . . . . . .<eB$<= < < < <=%HUOS(@"A =d = = = = = = = =r0   r7   c                   b    e Zd ZdZdefdZdededee	         fdZ
de	deeef         dd	fd
Zd	S )ProxyDescriptorzx
    Simple descriptor to enable setting of queries and filters as:

        s = Search()
        s.query = Q(...)

    namec                     d| d| _         d S )NrM   _proxy)r>   )r,   ra   s     r-   r?   zProxyDescriptor.__init__r   s    *d***r0   instanceownerr'   c                 h    t          t          t                   t          || j                            S r)   )r   r7   r4   rE   r>   )r,   rd   re   s      r-   __get__zProxyDescriptor.__get__u   s"    JrNGHdo$F$FGGGr0   rK   Nc                 X    t          || j                  }t          |          |_        d S r)   )rE   r>   r   r=   )r,   rd   rK   proxys       r-   __set__zProxyDescriptor.__set__x   s$     '$/ B B5r0   )r1   r2   r3   rY   rZ   r?   r   objectr7   r4   rg   r   rj   r*   r0   r-   r`   r`   i   s         +S + + + +H HF Hz"~ H H H H" "4S> "d " " " " " "r0   r`   c                   @     e Zd ZdZddZdeeef         f fdZ xZ	S )	AggsProxyaggsr8   SearchBase[_R]c                 P    t          d|           | _        || _        di i| _        d S )NzAgg[_R]rn   )r   _baser<   _params)r,   r8   s     r-   r?   zAggsProxy.__init__   s)    )T**
|r0   r'   c                     t          t          t          t          f         t	                                                                          di                     S )Nrn   )r   r   rZ   r   rQ   rO   get)r,   rS   s    r-   rO   zAggsProxy.to_dict   s9    DcNEGGOO$5$5$9$9&"$E$EFFFr0   )r8   ro   )
r1   r2   r3   ra   r?   r   rZ   r   rO   r]   r^   s   @r-   rm   rm   }   sp        D$ $ $ $
Gc3h G G G G G G G G G Gr0   rm   c                   T   e Zd Z	 	 	 	 ddedeeeee         f                  deeeeeeeef                  e	eeeef         f         f                  dee	ee
f                  fdZde
d	efd
Zd	efdZde
d	efdZdeeee         eedf         f         d	efdZded	ed         fdZ	 ddee
         dee         d	ee         fdZ	 ddee
         dee         d	efdZdeeef         deee
         ge
f         d	efdZded	efdZde
d	efdZd	efdZerd	e	ee
f         fdZdS dS )RequestdefaultNusingindexdoc_typeextrac                 F   || _         d | _        t          |t          t          f          rt	          |          | _        n
|r|g| _        g | _        i | _        t          |t          t          f          r| j                            |           nt          |t          j	        j
                  rG| j                            |                                           | j                            |           n|r| j                            |           i | _        |pi | _        d S r)   )_using_index
isinstancetuplelist	_doc_type_doc_type_mapextendcollectionsabcMappingkeysupdateappendrr   _extra)r,   rx   ry   rz   r{   s        r-   r?   zRequest.__init__   s	    eeT]++ 	"u++DKK 	" 'DK13-/h.. 	,N!!(+++++/"9:: 	,N!!(--//222%%h//// 	,N!!(+++')&+krr0   otherr'   c                     t          |t                    oY|j        | j        k    oI|j        | j        k    o9|j        | j        k    o)|                                |                                 k    S r)   )r   rv   rr   r~   r   rO   )r,   r   s     r-   __eq__zRequest.__eq__   sh    ug&& 2-2+2 4>12 4<<>>1	
r0   c                 *    |                                  S r)   )r.   r+   s    r-   __copy__zRequest.__copy__   s    {{}}r0   rC   c                 b    |                                  }|j                            |           |S )a  
        Specify query params to be used when executing the search. All the
        keyword arguments will override the current values. See
        https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.search
        for all available parameters.

        Example::

            s = Search()
            s = s.params(routing='user-1', preference='local')
        )r.   rr   r   r,   rC   rF   s      r-   paramszRequest.params   s,     KKMM		   r0   .c                 L   |                                  }|sd|_        ng }|D ]o}t          |t                    r|                    |           -t          |t
                    r||z  }Ht          |t                    r|t          |          z  }p| j        pg |z   |_        |S )a  
        Set the index for the search. If called empty it will remove all information.

        Example::

            s = Search()
            s = s.index('twitter-2015.01.01', 'twitter-2015.01.02')
            s = s.index(['twitter-2015.01.01', 'twitter-2015.01.02'])
        N)r.   r~   r   rZ   r   r   r   )r,   ry   rF   indexesis        r-   ry   zRequest.index   s     KKMM 	5AHHG ' 'a%% 'NN1%%%%4(( 'qLGG5)) 'tAww&G)rW4AHr0   pathr#   c                     | j         D ]A}t          |d          s|j                            |          }|t	          d|          c S Bd S )Nr~   r#   )r   hasattrr~   resolve_fieldr   )r,   r   dtfields       r-   _resolve_fieldzRequest._resolve_field   sc    . 	, 	,B2x(( I++D11E GU+++++ !tr0   hitparent_classc                 <   t           }g }|d         }|r:d|v r6|                    |d                    |                    d          }|rd|v 6d                    |          }|Dt	          |d          r4t          t          d         |j                            |                    }n.t          t          d         | 	                    |                    }|%t          t          t                   |j                  S t          t          t                   |          S )N_nestedr   .r~   r$   )r   r   rt   joinr   r   r
   r~   r   r   r   r   
_doc_class)r,   r   r   	doc_classnested_pathnestingnested_path_strnested_fields           r-   _resolve_nestedzRequest._resolve_nested   s    	i. 	-'W,,ww/000kk),,G  	-'W,, ((;// #h(G(G#"L$7$E$Eo$V$V LL  "D$7$7$H$H L #R,"9:::DHi(((r0   c                    t           }|                    d          }d|v r|                     ||          }nJ|| j        v r| j        |         }n3| j        D ]+}t          |d          r|                    |          r|} n,|                    dd          D ]4}t          t                   | |d         |         |          |d         |<   5t          |d|          }t          t           ||                    S )N_typer   _matches
inner_hitsr*   )r   from_es)r   rt   r   r   r   r   r   r   r   rE   r   )r,   r   r   r   r   rz   tcallbacks           r-   _get_resultzRequest._get_result  s    	WWW,,S,??II4%%%*2.II !N  8Z00 X5F5Fs5K5K  (IEr** 	 	A#+B<c,'*i$ $ $Ca   9i;;B&&&r0   c                    |                                  }|s|sg |_        i |_        n`|j                            |           |j                            |                                           |j                            |           |S )a  
        Set the type to search through. You can supply a single value or
        multiple. Values can be strings or subclasses of ``Document``.

        You can also pass in any keyword arguments, mapping a doc_type to a
        callback that should be used instead of the Hit class.

        If no doc_type is supplied any information stored on the instance will
        be erased.

        Example:

            s = Search().doc_type('product', 'store', User, custom=my_callback)
        )r.   r   r   r   r   r   )r,   rz   rC   rF   s       r-   rz   zRequest.doc_type  s    $ KKMM 	+ 	+AK AOOKx(((Kv{{}}---O""6***r0   clientc                 <    |                                  }||_        |S )a2  
        Associate the search request with an elasticsearch client. A fresh copy
        will be returned with current instance remaining unchanged.

        :arg client: an instance of ``elasticsearch.Elasticsearch`` to use or
            an alias to look up in ``elasticsearch.dsl.connections``

        )r.   r}   )r,   r   rF   s      r-   rx   zRequest.using:  s     KKMMr0   c                     |                                  }d|v r|                    d          |d<   |j                            |           |S )zf
        Add extra keys to the request body. Mostly here for backwards
        compatibility.
        from_from)r.   popr   r   r   s      r-   r{   zRequest.extraG  sJ    
 KKMMf#ZZ00F6N	r0   c                    |                      | j        | j        | j                  }| j                                        |_        | j                                        |_        | j                                        |_        |S )N)rx   ry   rz   )rS   r}   r~   r   r   copyr   rr   )r,   rF   s     r-   r.   zRequest._cloneR  sn    NN+T[4>  
 
 ,1133;##%%L%%''	r0   c                     d S r)   r*   r+   s    r-   rO   zRequest.to_dict]  r/   r0   )rw   NNNr)   ) r1   r2   r3   r   r
   r   rZ   r	   typer   r   r?   r[   r   r   r   r   r   ry   r   r    r   r   r   r   r   rz   rx   r{   r.   r   rO   r*   r0   r-   rv   rv      s        (15 *.2 22 c49n-.2 $T%c	"23T#uT3Y?O:O5PPQ
	2 S#X'2 2 2 2<
C 
D 
 
 
 
$    s t     E#tCy%S/"AB t    83 8G+<     BF) )C=)08)	b) ) ) )8 BF' 'C='08'	' ' ' '4tSy)5=x}os>R5S	   8L T    	c 	d 	 	 	 	      10T#s(^0000001 1r0   rv   c                   (    e Zd ZU  ee         d          Z ee         d          Zee         e	d<   de
f fdZde
de
defdZde
de
defd	Zd
eeef         defdZedeee
f         defd            Zdef fdZdeee                  defdZdeee
f         defdZde
defdZ	 	 	 	 	 	 d1deedf         dededeee                  deeee
f                  dee         dee         dee         deeee
f                  defdZd2deee eee
f         f                  defd Z!	 d2d!eee edeeedf                  eeeeedf                  f         f                  de
defd"Z"d#eedeeeeef         f         f         defd$Z#	 	 	 d3deeedf                  deeee
f                  d%ee         defd&Z$de
defd'Z%d!eedf         de
defd(Z&	 	 d4d)ed*ee         d+ee         de
def
d,Z'defd-Z(d5d/e de
deee
f         fd0Z) xZ*S )6
SearchBasequerypost_filter	_responserC   c                 x    t                      j        di | t          t                   |           | _        g | _        g | _        i | _        i | _        d| _	        i | _
        i | _        i | _        i | _        t          t                   | _        t!          | d          | _        t!          | d          | _        dS )a`  
        Search request to elasticsearch.

        :arg using: `Elasticsearch` instance to use
        :arg index: limit the search to index
        :arg doc_type: only query this type.

        All the parameters supplied (or omitted) at creation type can be later
        overridden by methods (`using`, `index` and `doc_type` respectively).
        Nr   r   r*   )rQ   r?   rm   r   rn   _sort_knn_rank	_collapse_source
_highlight_highlight_opts_suggest_script_fieldsr   _response_classr7   _query_proxy_post_filter_proxyr,   rC   rS   s     r-   r?   zSearchBase.__init__e  s     	""6"""bM$''	BD
*,	%'
)+OS*,/1(*.0'|&tW55",T="A"Ar0   rB   r'   c           	      ^    |                      t          t          |i |g                    S N)filterr   r   r   r,   rB   rC   s      r-   r   zSearchBase.filter  s/    zz$q$'9&'9'9&:;;;<<<r0   c           	      `    |                      t          t          |i | g                    S r   r   r   s      r-   excludezSearchBase.exclude  s2    zz$4(:6(:(:':&;<<<===r0   nc                    |                                  }t          |t                    rB|j        r|j        dk     s|j        r|j        dk     rt          d          |j        }|j        }n|dk     rt          d          |}|dz   }|j                            d          }d}d|j        v r|pd|j        d         z   }|}||pd|z   }|}||pd|z   }|||k     r|}|
||j        d<   |t          d||pdz
            |j        d<   |S )a	  
        Support slicing the `Search` instance for pagination.

        Slicing equates to the from/size parameters. E.g.::

            s = Search().query(...)[0:25]

        is equivalent to::

            s = Search().query(...).extra(from_=0, size=25)

        r   z)Search does not support negative slicing.z*Search does not support negative indexing.r   r   Nsize)	r.   r   slicestartstop
ValueErrorr   rt   max)	r,   r   rF   slice_start
slice_stopold_fromold_tonew_fromnew_tos	            r-   __getitem__zSearchBase.__getitem__  sJ    KKMMa 	w N17Q;;!&;QVaZZ !LMMM'KJJ 1uu !MNNNKQJ8<<''QXm!qx'77F" A4H!m!z1F!fvoo'AHV"1fA&>??AHVr0   dc                 D     |             }|                     |           |S )a  
        Construct a new `Search` instance from a raw dict containing the search
        body. Useful when migrating from raw dictionaries.

        Example::

            s = Search.from_dict({
                "query": {
                    "bool": {
                        "must": [...]
                    }
                },
                "aggs": {...}
            })
            s = s.filter('term', published=True)
        )update_from_dict)clsr   rF   s      r-   	from_dictzSearchBase.from_dict  s(    $ CEE	1r0   c                 b   t                                                      }| j        |_        d | j        D             |_        | j                                        |_        | j                                        |_        | j        dd         |_        | j        t          j        | j                  nd|_        | j	                                        |_	        | j
                                        |_
        | j                                        |_        | j                                        |_        dD ]*}t          | |          j        t          ||          _        +| j        j                            d          r0d| j        j        d                                         i|j        _        |S )z
        Return a clone of the current search request. Performs a shallow copy
        of all the underlying objects. Used internally by most state modifying
        APIs.
        c                 6    g | ]}|                                 S r*   )r   ).0knns     r-   
<listcomp>z%SearchBase._clone.<locals>.<listcomp>  s     222#((**222r0   N)r   r   rn   )rQ   r.   r   r   r   r   r   r   r   r   r   r   r   rE   r=   rn   rr   rt   )r,   rF   xrS   s      r-   r.   zSearchBase._clone  s`    GGNN 022	222*//##n))++*QQQ-/3|/GDIdl+++T	++-- 05577]''))
.3355) 	? 	?A%,T1%5%5%>GAqMM"" 9  (( 	H$di&7&?&D&D&F&FGAFNr0   r   c                 <    |                                  }||_        |S )zE
        Override the default wrapper used for the response.
        )r.   r   )r,   r   rF   s      r-   response_classzSearchBase.response_class  s     KKMMr0   c                    |                                 }d|v r,t          |                    d                    | j        _        d|v r,t          |                    d                    | j        _        |                    d|                    di                     }|r*dd |                                D             i| j        _        d|v rA|                    d          | _	        t          | j	        t                    r| j	        g| _	        d|v r|                    d          | _        d|v r|                    d          | _        d	|v r|                    d	          | _        d
|v r|                    d
          | _        d|v rH|                    d                                           }|                    d          | _        || _        d|v ro|                    d          | _        d| j        v rL| j                            d          }| j                                        D ]}|                    d|           d|v r|                    d          | _        | j                            |           | S )z
        Apply options from a serialized body to the current instance. Modifies
        the object in-place. Used mostly by ``from_dict``.
        r   r   rn   aggregationsc                 4    i | ]\  }}|t          |          S r*   )r   )r   ra   rK   s      r-   
<dictcomp>z/SearchBase.update_from_dict.<locals>.<dictcomp>  s$    JJJMT5qxxJJJr0   r   rankcollapsesortr   	highlightfieldssuggesttextscript_fields)r   r   r   r   r=   r   itemsrn   rr   r   r   dictr   r   r   r   r   r   r   values
setdefaultr   r   r   )r,   r   rn   highr   rF   s         r-   r   zSearchBase.update_from_dict  sG   
 FFHHa<<"#AEE'NN"3"3DJA()!%%*>*>(?(?D%uuVQUU>26677 	JJTZZ\\JJJ!DI A::eDI$)T** (!YK	Q;;vDJ??UU:..DNQ;;vDJ>>55++DL!55%%**,,D"hhx00DO#'D >>EE),,DM&&}((00--// / /ALL....a"#%%"8"8D1r0   c                     |                                  }|D ]*}t          ||         t                    rd||         i||<   +|j                            |           |S )ai  
        Define script fields to be calculated on hits. See
        https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html
        for more details.

        Example::

            s = Search()
            s = s.script_fields(times_two="doc['field'].value * 2")
            s = s.script_fields(
                times_three={
                    'script': {
                        'lang': 'painless',
                        'source': "doc['field'].value * params.n",
                        'params': {'n': 3}
                    }
                }
            )

        script)r.   r   rZ   r   r   )r,   rC   rF   ra   s       r-   r   zSearchBase.script_fields  se    * KKMM 	8 	8D&,,, 8 (&,7t	'''r0   Nr   r   knum_candidatesquery_vectorquery_vector_builderboostr   
similarityr   c
                 >   |                                  }
|
j                            t          |          ||d           ||t	          d          ||t	          d          |#t          t          |          |
j        d         d<   |||
j        d         d<   |||
j        d         d<   |Ht          |t                    r#|	                                |
j        d         d	<   n||
j        d         d	<   |||
j        d         d
<   |	|	|
j        d         d<   |
S )a  
        Add a k-nearest neighbor (kNN) search.

        :arg field: the vector field to search against as a string or document class attribute
        :arg k: number of nearest neighbors to return as top hits
        :arg num_candidates: number of nearest neighbor candidates to consider per shard
        :arg query_vector: the vector to search for
        :arg query_vector_builder: A dictionary indicating how to build a query vector
        :arg boost: A floating-point boost factor for kNN scores
        :arg filter: query to filter the documents that can match
        :arg similarity: the minimum similarity required for a document to be considered a match, as a float value
        :arg inner_hits: retrieve hits from nested field

        Example::

            s = Search()
            s = s.knn(field='embedding', k=5, num_candidates=10, query_vector=vector,
                      filter=Q('term', category='blog')))
        )r   r  r  Nz8one of query_vector and query_vector_builder is requiredz?only one of query_vector and query_vector_builder must be givenr	  r
  r  r   r  r   )
r.   r   r   rZ   r   r   r   r   r   rO   )r,   r   r  r  r	  r
  r  r   r  r   rF   s              r-   r   zSearchBase.knn6  sE   > KKMM	U"0 	
 	
 	
 $8$@WXXX#(<(HQ   #)-c<)@)@AF2J~&+1EAF2J-."'AF2Jw&%(( .'-~~'7'7r
8$$'-r
8$!'1AF2J|$!'1AF2J|$r0   rrfc                 h    |                                  }i |_        ||dur|du ri n||j        d<   |S )aa  
        Defines a method for combining and ranking results sets from a combination
        of searches. Requires a minimum of 2 results sets.

        :arg rrf: Set to ``True`` or an options dictionary to set the rank method to reciprocal rank fusion (RRF).

        Example::

            s = Search()
            s = s.query('match', content='search text')
            s = s.knn(field='embedding', k=5, num_candidates=10, query_vector=vector)
            s = s.rank(rrf=True)

        Note: This option is in technical preview and may change in the future. The syntax will likely change before GA.
        NFTr  )r.   r   )r,   r  rF   s      r-   r   zSearchBase.rankt  sC      KKMM?s%//#&$;;RRCAGENr0   r   c                    |                                  }|r|rt          d          t          dt          dt          fd            t          dddt          fd            t          dt          t
          t          df                  dt          t                   fd            t          dt          t          t          t
          t          df                  f         dt          t          t          t                   f         fd            dt
          t          dt          t
          t          df                  t          t          t          t
          t          df                  f         f         dt
          t          t          t                   t          t          t          t                   f         f         ffd	|)t          |t                    r|n
 |          |_	        |S |r!t          |j	        t                    si |_	        t          |j	        t                    rI|                                D ]4\  }}|	 |j	        |= # t          $ r Y w xY w |          |j	        |<   5|S )
a  
        Selectively control how the _source field is returned.

        :arg fields: field name, wildcard string, list of field names or wildcards,
                     or dictionary of includes and excludes
        :arg kwargs: ``includes`` or ``excludes`` arguments, when ``fields`` is ``None``.

        When no arguments are given, the entire document will be returned for
        each hit.  If ``fields`` is a string or list of strings, the field names or field
        wildcards given will be included. If ``fields`` is a dictionary with keys of
        'includes' and/or 'excludes' the fields will be either included or excluded
        appropriately.

        Calling this multiple times with the same named parameter will override the
        previous values with the new ones.

        Example::

            s = Search()
            s = s.source(includes=['obj1.*'], excludes=["*.description"])

            s = Search()
            s = s.source(includes=['obj1.*']).source(excludes=["*.description"])

        z6You cannot specify fields and kwargs at the same time.r   r'   c                     d S r)   r*   r   s    r-   ensure_stringsz)SearchBase.source.<locals>.ensure_strings  s    03r0   r   c                     d S r)   r*   r  s    r-   r  z)SearchBase.source.<locals>.ensure_strings  s    @Cr0   c                     d S r)   r*   r  s    r-   r  z)SearchBase.source.<locals>.ensure_strings  s	     r0   c                     d S r)   r*   r  s    r-   r  z)SearchBase.source.<locals>.ensure_strings  s	     $'3r0   c                     t          | t                    r fd|                                 D             S t          | t          t          f          sd | D             S t          |           S )Nc                 .    i | ]\  }}| |          S r*   r*   )r   r  vr  s      r-   r   z=SearchBase.source.<locals>.ensure_strings.<locals>.<dictcomp>  s)    HHHA>>!,,HHHr0   c                 ,    g | ]}t          |          S r*   )rZ   )r   fs     r-   r   z=SearchBase.source.<locals>.ensure_strings.<locals>.<listcomp>  s    ///1A///r0   )r   r  r   rZ   r   )r   r  s    r-   r  z)SearchBase.source.<locals>.ensure_strings  ss     &$'' 	#HHHHHHHH.?(@AA #
 0/////6{{"r0   )r.   r   r   rZ   r	   r   r   r   r[   r   r  r   KeyError)r,   r   rC   rF   keyrK   r  s         @r-   sourcezSearchBase.source  sp   L KKMM 	Wf 	WUVVV	3333333 
3	C#6C3CCC 
C		s$7789	#Y	 	 	 
	 
	'd5.A)A#BCCD	'#tCy.!	' 	' 	' 
	'	##U3 3345S$uS*=%=>??@B	# 3S	4T#Y#778	# 	# 	# 	# 	# 	#& ",VT":":Vv@V@VAIH 	*QY55 	AIai&& 	;$llnn ; ;
U=IcNN#    &4^E%:%:AIcNNs   =I
IIr   c                    |                                  }g |_        |D ]}t          |t                    st	          |          }|                    d          rD|dd         dk    rt          d          |j                            |dd         ddii           |j                            |           |j                            |           |S )a  
        Add sorting information to the search request. If called without
        arguments it will remove all sort requirements. Otherwise it will
        replace them. Acceptable arguments are::

            'some.field'
            '-some.other.field'
            {'different.field': {'any': 'dict'}}

        so for example::

            s = Search().sort(
                'category',
                '-title',
                {"price" : {"order" : "asc", "mode" : "avg"}}
            )

        will sort by ``category``, ``title`` (in descending order) and
        ``price`` in ascending order using the ``avg`` mode.

        The API returns a copy of the Search object and can thus be chained.
        -r   N_scorez$Sorting by `-_score` is not allowed.orderdesc)r.   r   r   r  rZ   rN   r   r   )r,   r   rF   r  
sort_fields        r-   r   zSearchBase.sort  s    2 KKMM 
	" 
	"Aa&& 	" VV
((-- /!!""~11./UVVVGNNJqrrNWf4E#FGGGGGNN:....q!!!!r0   max_concurrent_group_searchesc                     |                                  }i |_        ||S t          |          |j        d<   |r
||j        d<   |r
||j        d<   |S )a5  
        Add collapsing information to the search request.
        If called without providing ``field``, it will remove all collapse
        requirements, otherwise it will replace them with the provided
        arguments.
        The API returns a copy of the Search object and can thus be chained.
        Nr   r   r&  )r.   r   rZ   )r,   r   r   r&  rF   s        r-   r   zSearchBase.collapse  sc     KKMM=H"5zzG 	3(2AK%( 	Y;XAK78r0   c                 b    |                                  }|j                            |           |S )z
        Update the global highlighting options used for this request. For
        example::

            s = Search()
            s = s.highlight_options(order='score')
        )r.   r   r   r   s      r-   highlight_optionszSearchBase.highlight_options-  s-     KKMM	  (((r0   c                 f    |                                  }|D ]}||j        t          |          <   |S )a  
        Request highlighting of some fields. All keyword arguments passed in will be
        used as parameters for all the fields in the ``fields`` parameter. Example::

            Search().highlight('title', 'body', fragment_size=50)

        will produce the equivalent of::

            {
                "highlight": {
                    "fields": {
                        "body": {"fragment_size": 50},
                        "title": {"fragment_size": 50}
                    }
                }
            }

        If you want to have different options for different fields
        you can call ``highlight`` twice::

            Search().highlight('title', fragment_size=50).highlight('body', fragment_size=100)

        which will produce::

            {
                "highlight": {
                    "fields": {
                        "body": {"fragment_size": 100},
                        "title": {"fragment_size": 50}
                    }
                }
            }

        )r.   r   rZ   )r,   r   rC   rF   r  s        r-   r   zSearchBase.highlight9  s;    J KKMM 	* 	*A#)ALQ  r0   ra   r   regexc                 @   ||t          d          |r|rt          d          |rd|vrt          d          |                                 }|rd|i|j        |<   n|rd|v rd|i|j        |<   nd|i|j        |<   |j        |                             |           |S )	a  
        Add a suggestions request to the search.

        :arg name: name of the suggestion
        :arg text: text to suggest on

        All keyword arguments will be added to the suggestions body. For example::

            s = Search()
            s = s.suggest('suggestion-1', 'Elasticsearch', term={'field': 'body'})

        # regex query for Completion Suggester
            s = Search()
            s = s.suggest('suggestion-1', regex='py[thon|py]', completion={'field': 'body'})
        Nz,You have to pass "text" or "regex" argument.z4You can only pass either "text" or "regex" argument.
completionzC"regex" argument must be passed with "completion" keyword argument.r+  prefixr   )r   r.   r   r   )r,   ra   r   r+  rC   rF   s         r-   r   zSearchBase.suggestc  s    , <EMKLLL 	UE 	USTTT 	\//U   KKMM 	2 '/AJt 	2v%%$,d#3
4  $*D>
4 	
4'''r0   c                     t          | d          st          d          t          t          | j                                                  S )a"  
        Return a ``Search`` instance that retrieves the next page of results.

        This method provides an easy way to paginate a long list of results using
        the ``search_after`` option. For example::

            page_size = 20
            s = Search()[:page_size].sort("date")

            while True:
                # get a page of results
                r = await s.execute()

                # do something with this page of results

                # exit the loop if we reached the end
                if len(r.hits) < page_size:
                    break

                # get a search object with the next page of results
                s = s.search_after()

        Note that the ``search_after`` option requires the search to have an
        explicit ``sort`` order.
        r   z3A search must be executed before using search_after)r   r   r   r   r   search_afterr+   s    r-   r0  zSearchBase.search_after  sD    4 t[)) 	TRSSSD$.5577888r0   Fcountc                 v   i }| j         rt          | j                   |d<   | j        r3t          | j                  dk    r| j        d         |d<   n
| j        |d<   | j        r
| j        |d<   |s(| j        r)t          | j                                                  |d<   | j        j        r9|                    t          | j                                                             | j	        r
| j	        |d<   | j
        r
| j
        |d<   |                    t          | j                             | j        d	i fvr
| j        |d
<   | j        r,d| j        i|d<   |d                             | j                   | j        r
| j        |d<   | j        r
| j        |d<   |                    t          |                     |S )aI  
        Serialize the search into the dictionary that will be sent over as the
        request's body.

        :arg count: a flag to specify if we are interested in a body for count -
            no aggregations, no pagination bounds etc.

        All additional keyword arguments will be included into the dictionary.
        r   r   r   r   r   r   r   r   Nr   r   r   r   r   )r   r"   r   lenr   r   rO   rn   r   r   r   r   r   r   r   r   r   )r,   r1  rC   r   s       r-   rO   zSearchBase.to_dict  s    : 	7*4:66AgJ9 	%49~~""9Q<%9%: 	#
AfI  	9 Q#4T5E5M5M5O5O#P#P- y~ A*49+<+<+>+>??@@@z ' J&	~ / $*HH&t{33444|D":--#|) <"*DO!<++%%d&:;;;} -#})" 9%)%8/"	"6**+++r0   )NNNNNNr)   )NNN)NN)F)+r1   r2   r3   r`   r   r   r   r   r   __annotations__r   r?   r   r   r   intr   r   classmethodr   rZ   r   r.   r   r   r   r   r
   r	   floatr   r   r[   r   r  r   r   r)  r   r   r0  rO   r]   r^   s   @r-   r   r   `  s$        !OD!'**E'/$'66K|B B B B B B B8=C =3 =4 = = = =>S >C >D > > > >.U3:. .4 . . . .` $sCx. T    [*      4$x|"4     )$sCx. )T ) ) ) )Vc d    B /39=!%"&&*/3< <S--.< < 	<
 tE{+< 'tCH~6< < < UO< T#s(^,< 
< < < <| tT#s(^';!<=     @ _ _#U3 3345S$uS*=%=>??@	B
_ _ 
_ _ _ _B&3 3T#tCH~:M5NNO&	& & & &T <@/37;	 c#6678 T#s(^, (0}	
 
   4
# 
$ 
 
 
 
(S"556(BE(	( ( ( (Z ##	( (( sm( }	(
 ( 
( ( ( (T9d 9 9 9 9<6 6T 6S 6T#s(^ 6 6 6 6 6 6 6 6r0   r   c                        e Zd ZdZdef fdZdeeef         defdZ	de
ee                  fdZdef fdZd	ee         defd
Zdeeeef                  fdZ xZS )MultiSearchBasez`
    Combine multiple :class:`~elasticsearch.dsl.Search` objects into a single
    request.
    rC   c                 H     t                      j        di | g | _        d S )Nr*   )rQ   r?   	_searchesr   s     r-   r?   zMultiSearchBase.__init__  s+    ""6"""/1r0   r  r'   c                     | j         |         S r)   )r;  )r,   r  s     r-   r   zMultiSearchBase.__getitem__  s    ~c""r0   c                 *    t          | j                  S r)   )iterr;  r+   s    r-   __iter__zMultiSearchBase.__iter__  s    DN###r0   c                 p    t                                                      }| j        d d          |_        |S r)   )rQ   r.   r;  )r,   msrS   s     r-   r.   zMultiSearchBase._clone  s-    WW^^~aaa(	r0   r8   c                 b    |                                  }|j                            |           |S )a  
        Adds a new :class:`~elasticsearch.dsl.Search` object to the request::

            ms = MultiSearch(index='my-index')
            ms = ms.add(Search(doc_type=Category).filter('term', category='python'))
            ms = ms.add(Search(doc_type=Blog))
        )r.   r;  r   )r,   r8   rA  s      r-   addzMultiSearchBase.add  s,     [[]]
F###	r0   c                    g }| j         D ]~}i }|j        rt          t          |j                  |d<   |                    |j                   |                    |           |                    |                                           |S )Nry   )r;  r~   r   r   r   rr   r   rO   )r,   outrF   metas       r-   rO   zMultiSearchBase.to_dict  s    $& 	$ 	$A#%Dx 4 $S!( 3 3WKK	"""JJtJJqyy{{####
r0   )r1   r2   r3   rY   r   r?   r   r5  r   r   r   r   r   r?  r   r.   rC  r	   r   rZ   rO   r]   r^   s   @r-   r9  r9    s        
2 2 2 2 2 2 2#uS%Z0 #S # # # #$(:b>2 $ $ $ $      

*R. 
T 
 
 
 
d38n-        r0   r9  )5collections.abcr   r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   typing_extensionsr   r   rn   r   r   r   document_baser   
exceptionsr   r   r   r   r   responser   r   utilsr   r   r    r!   r"   r   r#   r$   r&   r4   r7   r`   rm   rv   r   r9  r*   r0   r-   <module>rN     s  $                                    " , + + + + + + + ! ! ! ! ! ! ! ! ! ! , , , , , , ( ( ( ( ( ( ! ! ! ! ! ! ! ! ! ! # # # # # # # # I I I I I I I I I I I I I I %$$$$$$$$" " " " "H " " " WT'''-= -= -= -= -= -= -= -=`" " " " "gbk " " "(	G 	G 	G 	G 	GW 	G 	G 	GT1 T1 T1 T1 T1gbk T1 T1 T1nA
 A
 A
 A
 A
 A
 A
 A
H, , , , ,gbk , , , , ,r0   