1

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.

4
  • On which field you want to run the query? Commented Jun 15, 2021 at 15:09
  • is there way to make it works for both 258 and 12416 Commented Jun 15, 2021 at 15:18
  • 12416 is a nested object or array? on which field of 12416 you want to do the query? Commented Jun 15, 2021 at 15:31
  • the problem that a can't set particular fields in query. Commented Jun 16, 2021 at 6:11

1 Answer 1

2

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"
    }
  }  
}
Sign up to request clarification or add additional context in comments.

2 Comments

Why query string will not work on nested field? Do you have any affirmation through documentation on this?
@Liastre There is this discussion on discuss.elastic.co/t/query-string-on-nested-objects/58587 . nested object is a different construct . there is a dedicated query to handle it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.