Trouble to understand some simple query

Hi,

i'm working with elasticsearch since some weeks now and I'm on the final step for my company project, but I have have some trouble to understand a trouble with a simple query.

in my index I have a nested field call "simulateur" which on conatins a "prettyName" and a "reference" field.

to filter my result I use this nested query for example:

              {
                "nested": {
                  "path": "simulateur",
                  "query": {
                    "query_string": {
                      "query": "BAT-EN-106",
                      "analyzer": "keyword",
                      "fields": [
                        "simulateur.reference"
                      ]
                    }
                  }
                }
              }

this one return me 0 result but I have an entry that must match the request:

{
  "took" : 32,
  "timed_out" : false,
  "_shards" : {
    "total" : 4,
    "successful" : 4,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "app_op_prod_2020-01-30-174513",
        "_type" : "offre_projet",
        "_id" : "56482",
        "_score" : null,
        "_source" : {
          ...
          "simulateur" : {
            "prettyName" : "Isolation des combles ou de toitures (Outremer TERTIAIRE)",
            "reference" : "BAT-EN-106"
          },
         ...
        },
        "sort" : [
          1573663408000
        ]
      }
    ]
  }
}

I don't understand why I have no result when I use the nested query.
if you need more information to be able to help me just ask.

I use elasticsearch 6.8
thanks in advance for those who will try to help me.

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

I will give a try as my index is generated with elastica from a sql database.

DELETE index
PUT index/_doc/1
{
  "reference": "XXX00001",
  "simulateur": {
    "prettyName": "Isolation des combles",
    "reference": "BAT-EN-106"
  }
}
GET index/_search
{
  "query": {
    "nested": {
      "path": "simulateur",
      "query": {
        "query_string": {
          "query": "BAT-EN-106",
          "analyzer": "keyword",
          "fields": [
            "simulateur.reference"
          ]
        }
      }
    }
  }
}

I can provide my elastica configuration if it's can help a bit more.

I found a solution by getting back to standard analizer with default_operator set to AND

here the nest query part:

{
                "nested": {
                  "path": "simulateur",
                  "query": {
                    "query_string": {
                      "query": "BAT-EN-106",
                      "default_operator": "AND",
                      "fields": [
                        "simulateur.reference"
                      ]
                    }
                  }
                }
              }

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