How i search firstname + lastname in elasticsearch

Hi Team,
firstname ,middlename and lastname are seperate fields in my index .
But i can't search firstname + middlename+lastname.
In mysql I used concat function .But Elasticsearch I do not find any option to do concat fields and search . Please gitve me an option to solve this

Hi Arun,
The bool query is the way to assemble Boolean logic like A OR B versus A AND B.
An example Kibana console script below to create and search for multiple fields:

DELETE test

POST test/_doc/1
{
  "firstName":"John",
  "lastName":"Smith"
}

GET test/_search
{
  "query": {
	"bool": {
	  "should": [
		{
		  "match": {
			"firstName": "john"
		  }
		},
		{
		  "match": {
			"lastName": "Smith"
		  }
		}
	  ]
	}
  }
}

This is not suitable for me . because I can't get firstname and lastname seperately .
Get only a text , that is not identify the firstname and lastname.
That's why iam rejecting this one.
So Only a solution to concat these fields and search with posting text

I'm confused now. Can you share some JSON?

If you've got one thing to search on but you want to search against more than one field, you could use a multi-match query.

my search term is a string . cannot identify firstname , lastname seperately in this string.

So I try to concat firstname +middlename+ lastname fields and execute wildcard query for checking like condition ?
This is not get right answer .

So What method Iam using for this search condition?

Can you share some sample documents in your index?

indent preformatted text by 4 spaces

 $params = [
            
    'index' => '142-contact',

            'body' => 

            [
                'settings' => 

                [
                    'number_of_shards' => 3,
                    'number_of_replicas' => 2,
                    "analysis"=>
                    [
                        "normalizer"=>[
                            "lowercase_normalizer"=> [
                                "type"=> "custom",
                                "filter"=> ["lowercase"]
                            ]
                        ]
                    ]
                ],
                'mappings' => [
                    // 'log' => 
                    // [
                        '_source' => [
                            'enabled' => true
                        ],
                        'properties' => 
                        [
                            'appId' => 
                            [
                                'type' => 'long',
                               
                            ],
                            'email' => 
                            [
                                'type' => 'keyword',
                                "doc_values"=> true,
                                "normalizer"=> "lowercase_normalizer"
                            ],
                            'id' => 
                            [
                                'type' => 'text'
                            ],
                            'last_viewed_date_time' => 
                            [
                                'type' => 'date'
                            ],
                            'owner_id' => 
                            [
                                'type' => 'keyword',
                                "doc_values"=> true,
                                "normalizer"=> "lowercase_normalizer"
                            ],
                            'master_record_id' => 
                            [
                                'type' => 'text'
                            ],
            
                            'salutation' => 
                            [
                                'type' => 'keyword',
                                "doc_values"=> true,
                                "normalizer"=> "lowercase_normalizer"
                            ],
                            'firstname' => 
                            [
                                'type' => 'keyword',
                                "doc_values"=> true,
                                "normalizer"=> "lowercase_normalizer"
                            ],
                            'lastname' => 
                            [
                                'type' => 'keyword',
                                "doc_values"=> true,
                                "normalizer"=> "lowercase_normalizer"
                            ],
                            'recordid' => 
                            [
                                'type' => 'long'
                            ]
                        ]
                    //]
                ]
            ]
        ];


         $response = $client->indices()->create($params);

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.

Multi Match Query with type = cross_fields will work.
Read the docs here - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields

Is like query supported in " cross_fields" ?.

firstname = "Will"
lastname="Smith"

GET /_search
{
"query": {
"multi_match" : {
"query": "Will Smith",
"type": "cross_fields",
"fields": [ "first_name", "last_name" ],
"operator": "and"
}
}
}

this query is working .

But I can search with " Like" condition .

eg :
GET /_search
{
"query": {
"multi_match" : {
"query": "Will S * ",
"type": "cross_fields",
"fields": [ "first_name", "last_name" ],
"operator": "and"
}
}
}

This is not work

Multi Match Query does not support Wildcard Queries. There's another workaround mentioned here - Multi_match with Wildcard?

Do you have a clear demarkation among the firstname and the lastname fields? Would be good if you can share a sample document, what you've shared above is just the mappings.

Hi

Multi_match with Wildcard?

is working , But could not get exact match . fetching so many other data also

eg;-
In one search term it will work fine

But , search term contain space , it will not work properly

here is an example , what i want

firstname = ''Will"
lastname = "Smith"

my search term is " Will Sm *"

How I find above firstname and lastname using this search term.

That is my requirement.

Please give me a solution

Hai

SELECT salutation,firstname, lastname FROM contact_fields WHERE CONCAT(salutation,firstname, lastname) like "%Mr.Swapni%"

This is the query iam using in mysql

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