# Cross field search with different analyzers

**URL:** <https://discuss.elastic.co/t/cross-field-search-with-different-analyzers/239765>\
**Category:** Elasticsearch\
**Created:** [July 3, 2020, 9:27am UTC](https://discuss.elastic.co/t/cross-field-search-with-different-analyzers/239765 "2020-07-03T09:27:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rathcke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rathcke/32/55661_2.png) [@rathcke](https://discuss.elastic.co/u/rathcke)\
**Post date:** [July 3, 2020, 9:27am UTC](https://discuss.elastic.co/t/cross-field-search-with-different-analyzers/239765/1 "2020-07-03T09:27:40Z")

</div>

I have the following (simplified) mapping:

```auto
{
"settings": {
    "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1"
    },
    "analysis": {
        "analyzer": {
            "rebuilt_whitespace": {
                "tokenizer": "whitespace",
                "filter": ["lowercase"]
            }
        }
    }
},
"mappings": {
    "properties": {
        "tags": {
            "fielddata": true,
            "type": "text",
            "analyzer": "rebuilt_whitespace",
            "fields": {
                "length": {
                    "type": "token_count",
                    "analyzer": "rebuilt_whitespace"
                }
            }
        },
        "category": {
            "type": "text",
            "fields": {
                "raw": {
                    "type": "keyword"
                }
            }
        }
    }
}
}

```

Say I have a query like "c++ programming" I'd like to be able to have results that match "programming" in category and "c++" in tags (but not "c"). Using cross\_fields (with multi\_match or query\_string) to do this doesn't work as they are using different analyzers. Anything else I have been able to find seem to go on compromise on something else. Also note I have more fields than those listed here, so doing "exhaustive" matching won't work.  
Basically I want to be able to perform:

`+(tags:programming | category:programming) +(tags:c++ | category:c)`

Note the different analyzers used for "c++". Is this possible?

---

<div class="post-metadata">

**Author:** ![rathcke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rathcke/32/55661_2.png) [@rathcke](https://discuss.elastic.co/u/rathcke)\
**Post date:** [July 7, 2020, 9:04am UTC](https://discuss.elastic.co/t/cross-field-search-with-different-analyzers/239765/2 "2020-07-07T09:04:12Z")

</div>

I haven't found a solution to this. Some threads a mentioning using `query_string` with `default_operator`set to `AND`, but this is still not giving me the right results.  
Alternatively, I can set `search_analyzer` at query time to force them into the same groups, but this is not optimal either.  
Any advice is greatly appreciated!

---

<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 4, 2020, 9:04am UTC](https://discuss.elastic.co/t/cross-field-search-with-different-analyzers/239765/3 "2020-08-04T09:04:19Z")

</div>

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