Home > database >  Search with fixed values for fields in in ElasticSeach
Search with fixed values for fields in in ElasticSeach

Time:08-28

I'm doing a project where I scraped the data from my country's constitution (Brazil), saved it in a pandas-like table and then converted it to csv and put it in ElasticSearch. I want to do a lookup with the value of two fixed columns (if it was sql) i.e. fields for ES.

If I were to do it in SQL, it would be:

SELECT text_field FROM constitution WHERE (field1= 'na') AND (field2= 'na')

So this search would return what I need, which is the text fields where my return is!!

How do I do this with ElasticSearch???

Ex: enter image description here

CodePudding user response:

Without the details like index and field names I can deduce the query below:

GET constitution/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": "na"
          }
        },
        {
          "match": {
            "field2": "na"
          }
        }
      ]
    }
  }
}

I suggest you read about bool queries.

  • Related