0
  {
    "global_string_mv": {
      "match_mapping_type": "string",
      "match": "global*_string_mv",
      "mapping": {
        "type": "text",
        "copy_to": "global_fields_string_mv",
        "fields": {
          "text_en": {
            "type": "text",
            "analyzer": "text_en_index",
            "search_analyzer": "text_en_query"
          },
          "text_en_shingle": {
            "type": "text",
            "analyzer": "text_shingle_en_index",
            "search_analyzer": "text_shingle_en_query"
          },
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }

In elastic we have copy_to parameter for copying the fields. Is there any way to replicate the same in mongodb while indexing????

UPDATE :-

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "last_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "full_name": {
        "type": "text"
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "first_name": "John",
  "last_name": "Smith"
}

GET my-index-000001/_search
{
  "query": {
    "match": {
      "full_name": { 
        "query": "John Smith",
        "operator": "and"
      }
    }
  }
}

The values of the first_name and last_name fields are copied to the full_name field.

The first_name and last_name fields can still be queried for the first name and last name respectively, but the full_name field can be queried for both first and last names.

In Elasticsearch, the copy_to parameter allows you to copy the values of multiple fields into a group field, which can then be queried as a single field.

Similarly we need to know that is this possible from mongodb ?? If it is possible then how ??

For more details refer to below link :- https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
  • For those of us unfamiliar with `elastic`, would you describe in more detail what you want to do with MongoDB? ... perhaps with example desired output documents? – rickhg12hs Sep 07 '22 at 12:57
  • Perhaps the MongoDB feature you are looking for is a [compound index](https://www.mongodb.com/docs/manual/core/index-compound/). A compound index will create an index on multiple fields and will be used when both fields are part of the query. – rickhg12hs Sep 08 '22 at 17:19

0 Answers0