Home > OS >  Merging fields in Elastic Search
Merging fields in Elastic Search

Time:01-20

I am pretty new to Elastic Search. I have a dataset with multiple fields like name, product_info, description etc., So while searching a document, the search term can come from any of these fields (let us call them as "search core fields"). If I start storing the data in elastic search, should I derive a field which is a concatenated term of all the "search core fields" ? and then index this field alone ?

I came across _all mapping concept and little confused. Does it do the same ?

CodePudding user response:

no, you don't need to create any new field with concatenated terms. You can just use _all with match query to search a text from any field. About _all, yes, it searches the text from any field

CodePudding user response:

The _all field has been removed in ES 7, so it would only work in ES 6 and previous versions. The main reason for this is that it used too much storage space.

However, you can define your own all field using the copy_to feature. You basically specify in your mapping which fields should be copied to your custom all field and then you can search on that field.

You can define your mapping like this:

PUT my-index
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "copy_to": "custom_all" 
      },
      "product_info": {
        "type": "text",
        "copy_to": "custom_all" 
      },
      "description": {
        "type": "text",
        "copy_to": "custom_all" 
      },
      "custom_all": {
        "type": "text"
      }
    }
  }
}

PUT my-index/_doc/1
{
  "name": "XYZ",
  "product_info": "ABC product",
  "description": "this product does blablabla"
}

And then you can search on your "all" field like this:

POST my-index/_search
{
  "query": {
    "match": {
      "custom_all": { 
        "query": "ABC",
        "operator": "and"
      }
    }
  }
}
  •  Tags:  
  • Related