How to concatenate 2 fields into one during query

2019-07-23 06:47发布

问题:

I have a document in solr which is already indexed and stored like

{
"title":"Harry potter",
"url":"http://harrypotter.com",
"series":[
           "sorcer's stone",
           "Goblin of fire",
          ]
}

My requirement is,during query time when I try to retrieve the document it should concatenate 2 fields in to and give the output like

{
  "title":"Harry potter",
"url":"http://harrypotter.com",
"series":[
           "sorcer's stone",
           "Goblin of fire",
          ],
"title_url":"Harry potter,http://harrypotter.com"
}

I know how to do it during index time by using URP but I'm not able to understand how to achieve this during query time.Could anyone please help me with this.Any sample code for reference would be a great help to me.Thanks for your time.

回答1:

concat function is available in solr7:

http://localhost:8983/solr/col/query?...&fl=title,url,concat(title,url)

if you are in an older solr, how difficult is to do this on the client side?



回答2:

To concat you can use concat(field1, field2).

There are many other functions to manipulate data while retrieving. You can see that here.