Doctor Josh Dubnau discusses some remarkably sophisticated behaviors in fruit flies that suggest that they do have cognition.
The question of whether flies have cognition depends a lot on what we mean by cognition. Fruit flies are remarkably sophisticated animals in the sense that they can court members of the opposite sex. They are able to find animals that are of the same species as they are, not a different fruit fly species but the same one, drosophila melanogaster courts drosophila melanogaster. Fruit flies are able to find appropriate food sources; they defend territory from other fruit flies. They’ll fight over access to a place to lay eggs, they are able to figure out what time of day is the most appropriate time to sleep and what is the most appropriate time to forage for food, and they can learn from their past experiences about what stimuli were noxious, or what stimuli (what smells, what sounds or what colors) were associated with something that tasted bad or something that was pleasing. Whether or not that was cognition, I’ll leave that to the philosophers.