Array -Query issue(Indexing vs query)

Hi ,
I have an array for field commodity line [3,35,1,11,12].I am trying to query the field for autocomplete results and i need output as 3 and 35 when i match with 3.My indexing works fine for all scenarios excpeting an array.
Is there an issue with my indexing or do i have to change my query.

Query used:
GET contracts/doc/_search
{

     "query":{
       "bool":{
         "filter":{
           "match_phrase":{
             "commodity_line.autocomplete":"3"
             
           }
         }
         
       }
     },
    "aggs":{
      "commodity":{
        "terms":{
          "field": "commodity_line.keyword"
          , "size":1000
        }
      }
    }
    }

Mapping:
PUT contracts
{

       "settings":{
          "analysis":{
             "filter":{
               
            
            "gramFilter": {
              
                 "type":     "edge_ngram",
                "min_gram" : 1,
                "max_gram" : 20,
              "token_chars": [
                "letter",
               "symbol",
                "digit"
              ]
            }
          
          },
             "analyzer":{
                
              
                  "autocomplete": { 
              "type": "custom",
              "tokenizer": "standard",
              "filter": [
                "lowercase",
                "trim",
                "gramFilter",
                 "asciifolding"
               
                
              ]
            }
            
              
          
          
             }
          }
          }
          
       ,
       "mappings":{
          "doc":{
             "properties":{
     "commodity_line" :{
                   "type":"text",
                  "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  },
                  
                  "autocomplete":{
                    "type":"text",
                    "analyzer":"autocomplete", 
                  "search_analyzer":"standard"
                  }
                  }
              
               
               }
    }
    }

I'm not sure what your query returns, but I suspect it matches the docs fine. However, I think you'll need to manually pull out the potentially matching values from your array field in your code/script.

Autocomplete looks for matches in fields, returning the doc with the match. Your doc has multiple matching values in the field in question, but it only returns the doc once.

You could otherwise index your data differently (denormalize further!) so that autocomplete returned the desired results.

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