Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Automate the writing of complex elastic requests

I get a string from my user that represents an elastic request. There can be the following types of requests:

Single term: TERM:MATCH_TERM ;

Several terms separated by AND: TERM:MATCH_TERM AND TERM:MATCH_TERM AND TERM:MATCH_TERM ;

Several terms separated by OR: `TERM:MATCH_TERM OR TERM:MATCH_TERM OR TERM:MATCH_TERM`` ;

Several terms separated by AND and OR: TERM:MATCH_TERM AND TERM:MATCH_TERM OR TERM:MATCH_TERM AND TERM:MATCH_TERM OR TERM:MATCH_TERM AND TERM:MATCH_TERM ;

I parse this string next and get a list of my different terms.

I want to use this list now to build my elastic query. I know I will have to use the syntax for complex queries: bool. (I use the javascript client of elastic to make my request)

From what I understand, the must filter will allow me to do an AND and the should filter will allow me to do an OR.

In the case where we have: TERM1:MATCH_TERM1 AND TERM2:MATCH_TERM2 OR TERM3:MATCH_TERM3 AND TERM4:MATCH_TERM4 OR TERM5:MATCH_TERM5 AND TERM6:MATCH_TERM6 ;

Would the correct syntax be something like this:

"query":{
    "bool":{ 
      "should":[
         "must":[
             {"terms":{"TERM1":"MATCH_TERM1"}}
         ] , 
         "must":[
             {"terms":{"TERM2":"MATCH_TERM2"}}
         ] , 
      ],
      "should":[
         "must":[
             {"terms":{"TERM3":"MATCH_TERM3"}}
         ] , 
         "must":[
             {"terms":{"TERM4":"MATCH_TERM4"}}
         ] , 
      ],
      "should":[
         "must":[
             {"terms":{"TERM5":"MATCH_TERM5"}}
         ] , 
         "must":[
             {"terms":{"TERM6":"MATCH_TERM6"}}
         ] , 
      ],
    }
  }

If there is any information missing to answer my question let me know and I will try to add it as soon as possible.

Thank you in advance if you take the time to help me.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda