1
votes

I have the following object in elastic.

Is there way to run a full text search query like: Fizz AND bar

{
  "258": "Fizz buzz",
  "12416": [
    {
      "161": 54,
      "273": "text doc.txt",
      "544": [
        "text/plain"
      ],
      "12290": "foo bar",
    }
  ]
}

I've read about Runtime fields but it supports only keyword type and will work only in case of full match.

1
On which field you want to run the query?Kaveh
is there way to make it works for both 258 and 12416Ilya
12416 is a nested object or array? on which field of 12416 you want to do the query?Kaveh
the problem that a can't set particular fields in query.Ilya

1 Answers

2
votes

Query string will not work on nested field. You can either use a nested query or implement a custom _all field

PUT index117
{
  
  "mappings": {
    "properties": {
      "_all":{
        "type": "text"
      },
      "258":{
        "type": "text",
        "copy_to": "_all"  --> copies data to _all field
      },
      "12416":{
        "type": "nested",
        "properties": {
          "12290":{
            "type":"text",
            "copy_to": "_all"
          }
        }
      }
    }
  }
}


POST index117/_doc
{
  "258": "Fizz buzz",
  "12416": [
    {
      "161": 54,
      "273": "text doc.txt",
      "544": [
        "text/plain"
      ],
      "12290": "foo bar"
    }
  ]
}

GET index117/_search
{
  "query": {
    "query_string": {
      "default_field": "_all",
      "query": "foo AND bar"
    }
  }  
}