0

my data is,

POST index_name/_doc/1
{
          "created_date" : "2023-02-09T13:21:41.632492",
          "created_by" : "hats",
          "data" : [
                        {
              "name" : "west cost",
              "document_id" : "1"
            },
            {
              "name" : "mist cost",
              "document_id" : "2"
            },
            {
              "name" : "cost",
              "document_id" : "3"
            }
          ]
        }
    

i used query_String to search

GET index_name/_serach
{
    "query_string": {
       "default_field": "data.name",
        "query": "*t cost"
    }
}

expected result was: west cost, mist cost

but the output was: west cost, mist cost, cost

i have tried many search query but still couldn't find a solution

which search query is used to handle the space, i need to search for the similar patterned value in the field

1
  • There is 1 document, and this document will match your query. So, you are expecting in this document to see 2 address inside the data, right? In the result 1 document will return but data array will have 2 object. Commented Feb 15, 2023 at 21:45

1 Answer 1

0

elasticsearch will return you the documents that satisfy the query, and your document 1 does satisfy the query, i.e., there is at least one item in the data array that has a name ending by *t cost. If you want only the first two data items to be returned in your response, you need to index each item independently in a separated document

Sign up to request clarification or add additional context in comments.

Comments

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.