# And operator does not work as expected

**URL:** <https://discuss.elastic.co/t/and-operator-does-not-work-as-expected/207053>\
**Category:** Elasticsearch\
**Created:** [November 8, 2019, 6:14am UTC](https://discuss.elastic.co/t/and-operator-does-not-work-as-expected/207053 "2019-11-08T06:14:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonaleeka\_dash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sonaleeka_dash/32/57356_2.png) [@sonaleeka\_dash](https://discuss.elastic.co/u/sonaleeka_dash)\
**Post date:** [November 8, 2019, 6:14am UTC](https://discuss.elastic.co/t/and-operator-does-not-work-as-expected/207053/1 "2019-11-08T06:14:21Z")

</div>

I have customField which is the combination of

customFieldTypeId and value .  
My Document content data something like this

For CustomeField.combined I want search using AND operator  
I tried something like this(tried MatchQuery as well ).

if I search for query "query": "58c35ebb-86e6-4b2f-a151-28b8ddd99919 Bangkok",  
it's give me data which has only 58c35ebb-86e6-4b2f-a151-28b8ddd99919 not bankok?  
I am expecting it to return all the hits which has both 58c35ebb-86e6-4b2f-a151-28b8ddd99919 Bangkok.  
Any suggestion what I am doing wrong

{  
"profile": true,  
"from": 0,  
"size": 15,  
"\_source": [  
"entity.names.fullName",  
"entity.customFields",  
"entity.names.caseId"  
],  
"sort": [  
{  
"entity.caseStatistics.countCategoriesByUnresolvedResults.Sanctions": {  
"order": "desc"  
}  
},  
{  
"entity.outstandingActions": {  
"order": "desc"  
}  
},  
{  
"entity.modificationDateByUser.utcDateTime": {  
"order": "desc"  
}  
},  
{  
"entity.modifier.lastName": {  
"order": "asc"  
}  
}  
],  
"query": {  
"bool": {  
"must": [  
{  
"bool": {  
"should": [  
{  
"query\_string": {

```
                                "fields": [
                                    "entity.customFields.combined"
                                ],
                                "query": "58c35ebb-86e6-4b2f-a151-28b8ddd99919 Bangkok",
                                "default_operator": "AND"
                               
                                
                                 
                                
                                
                            }
                        }
                        
                    ]
                }
            }
        ]
    }
}

```

}

Mysetting  
"settings": {  
"index": {  
"mapper": {  
"dynamic": "false"  
},  
"analysis": {  
"analyzer": {  
"custom\_icu\_analyzer": {  
"filter": [  
"lowercase"  
],  
"type": "custom",  
"tokenizer": "icu\_tokenizer"  
},  
"lowercase\_keyword": {  
"filter": [  
"lowercase"  
],  
"tokenizer": "keyword"  
},  
"ducet\_sort": {  
"filter": [  
"icu\_collation"  
],  
"tokenizer": "keyword"  
}  
}  
}  
}  
}

And Costume Field looks something like this

"customFields": [ {

```
                            "customFieldTypeId": "ab75e581-c31e-4b86-a81b-3f331f2ddcce",
                            "combined": "ab75e581-c31e-4b86-a81b-3f331f2ddcce|Andrew Wilson",
                            "value": "Andrew Wilson"
                          },
                       {
                            "customFieldTypeId": "97d5f242-b689-473e-a4cc-4a6ddbd4aae3",
                            "combined": "97d5f242-b689-473e-a4cc-4a6ddbd4aae3|Canada,Square TEST",
                            "value": "Canada,Square TEST"
                       
                       },
                       {
                            "customFieldTypeId": "8ee59ec9-bf6d-4c9c-8528-882412a1ea1f",
                            "combined": "8ee59ec9-bf6d-4c9c-8528-882412a1ea1f|Migration",
                            "value": "Migration"
                       
                       },
                           { "customFieldTypeId": "9af3ca31-56a1-4de9-a2f2-2308ba96c236",
                            "combined": "9af3ca31-56a1-4de9-a2f2-2308ba96c236|Santiago Del Estero,Argentina",
                            "value": "Santiago Del Estero,Argentina"
                           },
                        {
                            "customFieldTypeId": "58c35ebb-86e6-4b2f-a151-28b8ddd99919",
                            "combined": "58c35ebb-86e6-4b2f-a151-28b8ddd99919|A-00193476",
                            "value": "A-00193476"
                        
                        },
                        {
                            "customFieldTypeId": "ebaff5a9-2a8a-494e-a7ec-0d667a46e433",
                            "combined": "ebaff5a9-2a8a-494e-a7ec-0d667a46e433|18672_Batch 2 Finance Current Cust.csv_1349201800270",
                            "value": "18672_Batch 2 Finance Current Cust.csv_1349201800270"
                        }
                            
    ],
```

---

<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:** [December 6, 2019, 6:14am UTC](https://discuss.elastic.co/t/and-operator-does-not-work-as-expected/207053/2 "2019-12-06T06:14:25Z")

</div>

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