Advise needed

How to search combining 3 fields in the same document in elastic search. Like if Sachin Tendulkar is in 3 fields sachin tendu lkar. Combine 3 fields and search in it

Note :I don't want to use copy to that's used in index creation

Hi,
I'm not sure I understood the problem, would you please provide a real-case example?

However, technically, you can combine fields at search time by using the script query (see the documentation), e.g.,

{
  "query": {
    "script": {
      "script": {
        "source": """
        doc['field1'].value + doc['field2'].value + doc['field3'].value == "Sachin Tendulkar"
        """
      }
    }
  }
}

But I'm pretty sure we'll find a better solution, once better understood the problem :slight_smile:

Hi

Script isn't working even with direct field search.pls advise

{

"query":{

"script": {

"script":{

"source":"doc['Entid'].value == 'AHIJ' "

}

}

}

}

Thanks

Dinesh

What does it mean that it's not working? Did you get an error or just not what you expected?

Anyway, we need a bit more information on your problem, i.e., how does the documents look like, what is the mapping, and what is the exact query you'd like to run.

Hi
My requirement is wild card search (contains) across multiple fields in the same document at search time.pls give a sample query and any specific requirements to achieve this.

I will send the script that dint work tomorrow.

Thanks

Dinesh

Correction below

Any update.... I tried query string but it does not do search over concatenated fields... Say if I search for INTR where IN is last 2 byte of field1 and TR is first 2 byte of field2 it doesn't get me result... When script is applied ,first the query is executed then only script is done over it so I couldnt able to use script with query string too pls do the needful

Thanks

Dinesh

Why not using the copy_to feature?

Hi
I want to achieve this at search time not at index time... Copy to does at index creation time.... Help me to achieve this at search time

Thanks

Dinesh

You can use the multi_match query which allows you searching in multiple fields at the same time. See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

Looks like cross field search under it can solve my problem.but not sure if one word is split under 2 fields can it search in 2 fields combinely. If Mark is stored in 2 fields MA in field1 and RK in field 2 ,can searching mark with cross field finds it......Let me work out

Thanks

Dinesj

I tried multi match but it's not searching word that is splitted across fields as I mentioned earlier....if I want to search India where Ind is in field 1 and ia is in field 2 ... But give me search time query to accomplish this

Thanks

Dinesh

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

I do not think this is possible and would recommend that you correct/restructure your input data before indexing so you do not have words split across fields and/or use the copy to functionality. The structure of the data determines how it is indexed and although you might be able to combine fields and use a script at search time this will not allow you to use all the search capabilities of Elasticsearch as the data is not indexed correctly and is also likely to be very slow.

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