Deep search, Searching by number

I have a products index. Its structure is :

[
    {
        "id": 1,
        "name": "IPhone 11",
        "quantity_stock": 100,
        "description": "description of IPhone 11",
        "manufacturing": {
            "id": 416665497,
            "entreprise": "Apple",
            "country": "USA",
            "address": {
                "zipCode": "10000",
                "state": "New York",
                "street": "Johny 10"
            }
        }
    },
    {
        "id": 2,
        "name": "Samsung 10",
        "quantity_stock": 130,
        "description": "description of Samsung 10",
        "manufacturing": {
            "id": 4545465497,
            "entreprise": "Samsung",
            "country": "Koea",
            "address": {
                "zipCode": "20000",
                "state": "Tokyo",
                "street": "yong ki 645"
            }
        }
    },
    {
        "id": 3,
        "name": "Redmi Note 10",
        "quantity_stock": 80,
        "description": "description of Redmi Note 10",
        "manufacturing": {
            "id": 4545465497,
            "entreprise": "Samsung",
            "country": "China",
            "address": {
                "zipCode": "14000",
                "state": "Pekin",
                "street": "yong ki 10"
            }
        }
    }
]

I want to have some deep search by number, like searching by manufacturing id for products index.

I tried something like this, but didn’t work :

// I use Nest.js package (@nestjs/elasticsearch)
// I try to get products by manufactoring id
// ❌ Din't Work ❌
async searchById(manufacturingId: number) {
    const products = await this.esService.search<any>({
      index: 'products',
      body: {
        query: {
          match: {
            manufacturing: {
              id: manufacturingId,
            },
          },
        },
      },
    });
    return products;
  }

Please, I get stuck to resolve this.
can anyone help me, or give an idea or ressources to solve this.

Kind regards.

Hi @sadiki-dev .

Maybe this works:

{
  "query": {
    "match": {
      "manufacturing.id": 416665497
    }
  }
}

or

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "manufacturing.id": 416665497
          }
        }
      ]
    }
  }
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.