djangoelasticsearchelasticsearch-dslelasticsearch-dsl-py

Searching through an array in an Elasticsearch field


I have a collection of Elasticsearch documents that look something like this:

  {
    "_score": 1,
    "_id": "inv_s3l9ly4d16csnh1b",
    "_source": {
      "manufacturer_item_id": "OCN1-1204P-ARS4",
      "description": "TLX Headlight",
      "ext_invitem_id": "TDF30907",
      "tags": [
        {
          "tag_text": "Test Tag"
        }
      ],
      "id": "inv_s3l9ly4d16csnh1b",
    },
    "_index": "parts"
  }

I want to able to search for documents by tag_text under tags, but I also want to search other fields. I put together a multi_match query that looks like this:

{
  "query": {
    "multi_match": {
      "query": "Test Tag",
      "type": "cross_fields",
      "fields": [
        "tags",
        "description"
      ]
    }
  }
}

But I don't get any results. Can someone tell me what's wrong with my query?


Solution

  • Okay, turns out that I was doing something silly. I got my expected results using this query:

    {
      "query": {
        "multi_match": {
          "query": "Test Tag",
          "type": "cross_fields",
          "fields": [
            "tags.tag_text",
            "description"
          ]
        }
      }
    }