Multiple field search is not working in field having array of object in Elasticsearch 6

Here is the type of document i have:

{
"id": 41,
"invoice_number": "INV-0022",
"order_number": null,
"status": "Draft",
"object_id": "invoice_41",
"viewed_date": null,
"total_amount": 21640,
"total_amount_formatted": "₹ 21,640.00",
"invoice_date_formatted": "16/08/23",
"customer_viewed": null,
"viewed_date_formatted": false,
"balance_due": 21640,
"balance_due_formatted": "₹ 21,640.00",
"due_date_formatted": "16/08/23",
"customer_id": 3,
"updated_at": "2016-08-24 19:41:59",
"created_at": "2016-08-23 16:39:57",
"recurring_id": null,
"party": {
"display_name": "MANI RAM BALWANT RAI",
"contacts": [
{
"name": "BALWANT",
"email": "EFF@GMAIL.COM",
"mobile": "9988000000",
"phone": "2533433"
}
]
},
"status_formatted": "Draft",
"tags": [
"invoice"
,
"organization_id_11"
,
"Draft"
]
},
"sort": [
1471970397000
]
}

Here is my query:

{
  "query": {
    "multi_match": {
      "query": "ram",
      "fields": [
        "invoice_number",
        "status",
        "party.display_name",
        "party.contacts"
      ]
    }
  },
  "sort": {
    "created_at": "desc"
  }
}

When i have query "ram" it results perfectly fine. But when my query is "EFF@GMAIL.COM", it is not resulting any hits. Here i'm expecting this to be searched in array of party.contacts. I don't know how to refer all elements of party.contacts field.

Any reference will be helpful.
Thanks

You can use wildcards to query multiple child fields, like this: party.contacts.*.

The full query would look like this:

{
  "query": {
    "multi_match": {
      "query": "ram",
      "fields": [
        "invoice_number",
        "status",
        "party.display_name",
        "party.contacts.*"
      ]
    }
  },
  "sort": {
    "created_at": "desc"
  }
}

Hi,

Thanks for your reply.

In this case, keeping following query should also work. BTW Is there any performance concern i should be aware about?

   {
  "query": {
    "multi_match": {
      "query": "ram",
      "fields": [
        "invoice_number",
        "status",
        "party.*"
      ]
    }
  },
  "sort": {
    "created_at": "desc"
  }
}

Generally, the more fields you query, the more expensive the query generally is going to be. Looking at your sample document it does not seem like you will be querying an excessive amount of fields though.

BTW, i tried with wild character but it did not work.

Actually it is working when i give exact case to be searched. my search query is EFF@GMAIL.COM. So i have to keep the exact case. Otherwise it is working fine on rest of the fields.

thank.

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