How to concatenate 2 fields into one during query

2019-07-23 06:34发布

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.

2条回答
叛逆
2楼-- · 2019-07-23 07:21

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?

查看更多
看我几分像从前
3楼-- · 2019-07-23 07:23

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

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

查看更多
登录 后发表回答