# Custom plugin for search

**URL:** <https://discuss.elastic.co/t/custom-plugin-for-search/190809>\
**Category:** Elasticsearch\
**Created:** [July 16, 2019, 6:03pm UTC](https://discuss.elastic.co/t/custom-plugin-for-search/190809 "2019-07-16T18:03:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![toloo](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@toloo](https://discuss.elastic.co/u/toloo)\
**Post date:** [July 16, 2019, 6:03pm UTC](https://discuss.elastic.co/t/custom-plugin-for-search/190809/1 "2019-07-16T18:03:44Z")

</div>

Hello,

I'm new to Elasticsearch. I'm looking to write a plugin that at search time, it only looks at some specific sub-fields based on the search query. For example, with the following example I only want to get "Cat Fred" as the result by only looking at text.Cat subfield. I cloned the source code and implemented this behavior by changing the fromXContent method in MultiMatchQueryBuilder.java. Can someone help me how I can override this method somehow in a plugin?

Example:

```
PUT my_index
{
  "mappings": {
    "properties": {
      "text": { 
        "type": "text",
        "fields": {
          "Dog": {
            "type": "text",
            "analyzer": "english"
          },
          "Cat": {
            "type": "text",
            "analyzer": "english"
          }
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "text" : "Cat Fred"
}

PUT my_index/_doc/2
{
  "text" : "Dog Fred"
}

GET my_index/_search
{
  "query": {
    "multi_match": {
      "query": "Fred",
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 13, 2019, 6:03pm UTC](https://discuss.elastic.co/t/custom-plugin-for-search/190809/2 "2019-08-13T18:03:45Z")

</div>

Closed on August 13, 2019, 6:03pm UTC

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